You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dr...@apache.org on 2010/03/09 06:20:24 UTC
svn commit: r920689 - in /incubator/thrift/trunk/lib/cpp/src/server:
TNonblockingServer.cpp TNonblockingServer.h
Author: dreiss
Date: Tue Mar 9 05:20:24 2010
New Revision: 920689
URL: http://svn.apache.org/viewvc?rev=920689&view=rev
Log:
cpp: Don't leak memory on realloc failure in TNonblockingServer
Modified:
incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp
incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.h
Modified: incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp?rev=920689&r1=920688&r2=920689&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp (original)
+++ incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp Tue Mar 9 05:20:24 2010
@@ -128,15 +128,18 @@ void TConnection::workSocket() {
// Double the buffer size until it is big enough
if (readWant_ > readBufferSize_) {
- while (readWant_ > readBufferSize_) {
- readBufferSize_ *= 2;
+ uint32_t newSize = readBufferSize_;
+ while (readWant_ > newSize) {
+ newSize *= 2;
}
- readBuffer_ = (uint8_t*)std::realloc(readBuffer_, readBufferSize_);
- if (readBuffer_ == NULL) {
+ uint8_t* newBuffer = (uint8_t*)std::realloc(readBuffer_, newSize);
+ if (newBuffer == NULL) {
GlobalOutput("TConnection::workSocket() realloc");
close();
return;
}
+ readBuffer_ = newBuffer;
+ readBufferSize_ = newSize;
}
// Read from the socket
Modified: incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.h
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.h?rev=920689&r1=920688&r2=920689&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.h (original)
+++ incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.h Tue Mar 9 05:20:24 2010
@@ -708,6 +708,7 @@ class TConnection {
}
~TConnection() {
+ std::free(readBuffer_);
server_->decrementNumConnections();
}