Fix a memory leak in TBinaryProtocol.

Summary:
realloc doesn't free the original pointer when it returns null.

Reviewed By: cpiro

Test Plan: make check

TracCamp Project: Thrift

Revert Plan: ok


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665626 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/protocol/TBinaryProtocol.cpp b/lib/cpp/src/protocol/TBinaryProtocol.cpp
index b3e9fbc..2d98395 100644
--- a/lib/cpp/src/protocol/TBinaryProtocol.cpp
+++ b/lib/cpp/src/protocol/TBinaryProtocol.cpp
@@ -406,11 +406,11 @@
 
   // Use the heap here to prevent stack overflow for v. large strings
   if (size > string_buf_size_ || string_buf_ == NULL) {
-    string_buf_ = (uint8_t*)std::realloc(string_buf_, (uint32_t)size);
-    if (string_buf_ == NULL) {
-      string_buf_size_ = 0;
+    void* new_string_buf = std::realloc(string_buf_, (uint32_t)size);
+    if (new_string_buf == NULL) {
       throw TProtocolException(TProtocolException::UNKNOWN, "Out of memory in TBinaryProtocol::readString");
     }
+    string_buf_ = (uint8_t*)new_string_buf;
     string_buf_size_ = size;
   }
   trans_->readAll(string_buf_, size);