From 0c84f2deff74040a25ecbe4ca73c2488d3f290a5 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 15 Jun 2010 10:02:34 +0000 Subject: [PATCH] From Cedric Pinson, "Here a fix about a leak in InputStream::decompress I changed _in->setStream( new std::stringstream(data) ); to _dataDecompress = new std::stringstream(data); _in->setStream( _dataDecompress ); Then when the destructor is of InputStream is called I delete the dataDecompress stringstream. " --- include/osgDB/InputStream | 3 +++ src/osgDB/InputStream.cpp | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/osgDB/InputStream b/include/osgDB/InputStream index d84d294db..5c1ab61f4 100644 --- a/include/osgDB/InputStream +++ b/include/osgDB/InputStream @@ -167,6 +167,9 @@ protected: osg::ref_ptr _in; osg::ref_ptr _exception; osg::ref_ptr _options; + + // store here to avoid a new and a leak in InputStream::decompress + std::stringstream* _dataDecompress; }; void InputStream::throwException( const std::string& msg ) diff --git a/src/osgDB/InputStream.cpp b/src/osgDB/InputStream.cpp index 32f1023ae..09f4d7d84 100644 --- a/src/osgDB/InputStream.cpp +++ b/src/osgDB/InputStream.cpp @@ -24,7 +24,7 @@ using namespace osgDB; static std::string s_lastSchema; InputStream::InputStream( const osgDB::Options* options ) -: _byteSwap(0), _useFloatMatrix(true), _useSchemaData(false), _forceReadingImage(false) + : _byteSwap(0), _useFloatMatrix(true), _useSchemaData(false), _forceReadingImage(false), _dataDecompress(0) { if ( !options ) return; _options = options; @@ -73,6 +73,8 @@ InputStream::InputStream( const osgDB::Options* options ) InputStream::~InputStream() { + if (_dataDecompress) + delete _dataDecompress; } InputStream& InputStream::operator>>( osg::Vec2b& v ) @@ -672,8 +674,9 @@ void InputStream::decompress() if ( !compressor->decompress(*(_in->getStream()), data) ) throwException( "InputStream: Failed to decompress stream." ); if ( getException() ) return; - - _in->setStream( new std::stringstream(data) ); + + _dataDecompress = new std::stringstream(data); + _in->setStream( _dataDecompress ); _fields.pop_back(); }