Author: dreiss
Date: Tue Mar  9 05:20:19 2010
New Revision: 920687

URL: http://svn.apache.org/viewvc?rev=920687&view=rev
Log:
cpp: Prevent TFileTransport seekToEnd from leaking memory

In seekToEnd we loop on readEvent to skip through the last chunk, but
the complete events returned are disowned by readState_ and therefore
must be freed by the caller.

Modified:
    incubator/thrift/trunk/lib/cpp/src/transport/TFileTransport.cpp
    incubator/thrift/trunk/lib/cpp/src/transport/TFileTransport.h

Modified: incubator/thrift/trunk/lib/cpp/src/transport/TFileTransport.cpp
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/transport/TFileTransport.cpp?rev=920687&r1=920686&r2=920687&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/transport/TFileTransport.cpp (original)
+++ incubator/thrift/trunk/lib/cpp/src/transport/TFileTransport.cpp Tue Mar  9 
05:20:19 2010
@@ -43,6 +43,7 @@
 
 namespace apache { namespace thrift { namespace transport {
 
+using boost::scoped_ptr;
 using boost::shared_ptr;
 using namespace std;
 using namespace apache::thrift::protocol;
@@ -529,6 +530,7 @@ uint32_t TFileTransport::read(uint8_t* b
   return len;
 }
 
+// note caller is responsible for freeing returned events
 eventInfo* TFileTransport::readEvent() {
   int readTries = 0;
 
@@ -763,7 +765,13 @@ void TFileTransport::seekToChunk(int32_t
     uint32_t oldReadTimeout = getReadTimeout();
     setReadTimeout(NO_TAIL_READ_TIMEOUT);
     // keep on reading unti the last event at point of seekChunk call
-    while (readEvent() && ((offset_ + readState_.bufferPtr_) < minEndOffset)) 
{};
+    boost::scoped_ptr<eventInfo> event;
+    while ((offset_ + readState_.bufferPtr_) < minEndOffset) {
+      event.reset(readEvent());
+      if (event.get() == NULL) {
+        break;
+      }
+    }
     setReadTimeout(oldReadTimeout);
   }
 

Modified: incubator/thrift/trunk/lib/cpp/src/transport/TFileTransport.h
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/transport/TFileTransport.h?rev=920687&r1=920686&r2=920687&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/transport/TFileTransport.h (original)
+++ incubator/thrift/trunk/lib/cpp/src/transport/TFileTransport.h Tue Mar  9 
05:20:19 2010
@@ -29,6 +29,7 @@
 
 #include <pthread.h>
 
+#include <boost/scoped_ptr.hpp>
 #include <boost/shared_ptr.hpp>
 
 namespace apache { namespace thrift { namespace transport {


Reply via email to