THRIFT-926. cpp: Thrift: throw bad_alloc when malloc fails, not something else

When malloc/realloc fail, we've typically just thrown a TException. This
allows a server that should simply crash when out of memory to survive
in a strage state, with various bad consequences. Instead, we should
throw bad_alloc and just not catch it (or if we decide to, be very
careful to respond properly).

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@1005167 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/protocol/TBinaryProtocol.tcc b/lib/cpp/src/protocol/TBinaryProtocol.tcc
index 1433a4f..0f1c34a 100644
--- a/lib/cpp/src/protocol/TBinaryProtocol.tcc
+++ b/lib/cpp/src/protocol/TBinaryProtocol.tcc
@@ -435,8 +435,7 @@
   if (size > this->string_buf_size_ || this->string_buf_ == NULL) {
     void* new_string_buf = std::realloc(this->string_buf_, (uint32_t)size);
     if (new_string_buf == NULL) {
-      throw TProtocolException(TProtocolException::UNKNOWN,
-                               "Out of memory in TBinaryProtocolT::readString");
+      throw std::bad_alloc();
     }
     this->string_buf_ = (uint8_t*)new_string_buf;
     this->string_buf_size_ = size;
diff --git a/lib/cpp/src/protocol/TCompactProtocol.tcc b/lib/cpp/src/protocol/TCompactProtocol.tcc
index 2448146..8ad999c 100644
--- a/lib/cpp/src/protocol/TCompactProtocol.tcc
+++ b/lib/cpp/src/protocol/TCompactProtocol.tcc
@@ -679,7 +679,7 @@
   if (size > string_buf_size_ || string_buf_ == NULL) {
     void* new_string_buf = std::realloc(string_buf_, (uint32_t)size);
     if (new_string_buf == NULL) {
-      throw TProtocolException(TProtocolException::UNKNOWN, "Out of memory in TCompactProtocol::readString");
+      throw std::bad_alloc();
     }
     string_buf_ = (uint8_t*)new_string_buf;
     string_buf_size_ = size;