From 58b4fa7e26648cf5251029f6ebb73a4c86129354 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Tue, 1 Apr 2008 04:17:58 +0000 Subject: [PATCH] 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 --- lib/cpp/src/protocol/TBinaryProtocol.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cpp/src/protocol/TBinaryProtocol.cpp b/lib/cpp/src/protocol/TBinaryProtocol.cpp index b3e9fbcc..2d983951 100644 --- a/lib/cpp/src/protocol/TBinaryProtocol.cpp +++ b/lib/cpp/src/protocol/TBinaryProtocol.cpp @@ -406,11 +406,11 @@ uint32_t TBinaryProtocol::readStringBody(string& str, int32_t size) { // 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); -- 2.17.1