From: <syn...@us...> - 2009-04-12 17:12:50
|
Revision: 2987 http://clucene.svn.sourceforge.net/clucene/?rev=2987&view=rev Author: synhershko Date: 2009-04-12 17:12:31 +0000 (Sun, 12 Apr 2009) Log Message: ----------- * Fixes memory leak in StringBuffer which was introduced in revision 2948 * Tweaks Token::growBuffer by using new/delete[] instead of realloc since a memory copy is being performed right after it anyway Revision Links: -------------- http://clucene.svn.sourceforge.net/clucene/?rev=2948&view=rev Modified Paths: -------------- branches/lucene2_3_2/src/core/CLucene/analysis/AnalysisHeader.cpp branches/lucene2_3_2/src/shared/CLucene/util/StringBuffer.cpp Modified: branches/lucene2_3_2/src/core/CLucene/analysis/AnalysisHeader.cpp =================================================================== --- branches/lucene2_3_2/src/core/CLucene/analysis/AnalysisHeader.cpp 2009-04-12 13:42:34 UTC (rev 2986) +++ branches/lucene2_3_2/src/core/CLucene/analysis/AnalysisHeader.cpp 2009-04-12 17:12:31 UTC (rev 2987) @@ -67,7 +67,8 @@ Token::~Token(){ #ifndef LUCENE_TOKEN_WORD_LENGTH - free(_termText); + //free(_termText); + delete[] _termText; #endif _CLLDELETE(payload); } @@ -148,9 +149,16 @@ return; #ifndef LUCENE_TOKEN_WORD_LENGTH if ( _termText == NULL ) - _termText = (TCHAR*)malloc( size * sizeof(TCHAR) ); - else - _termText = (TCHAR*)realloc( _termText, size * sizeof(TCHAR) ); + //_termText = (TCHAR*)malloc( size * sizeof(TCHAR) ); + _termText = new TCHAR[size * sizeof(TCHAR)]; + else{ + // ISH: Use new/delete[] instead of realloc, since a copy is being made anyway and there's no + // need to preserve the current content + //_termText = (TCHAR*)realloc( _termText, size * sizeof(TCHAR) ); + TCHAR* __termText = new TCHAR[size * sizeof(TCHAR)]; + delete[] _termText; + _termText = __termText; + } bufferTextLen = size; #else _CLTHROWA(CL_ERR_TokenMgr,"Couldn't grow Token buffer"); Modified: branches/lucene2_3_2/src/shared/CLucene/util/StringBuffer.cpp =================================================================== --- branches/lucene2_3_2/src/shared/CLucene/util/StringBuffer.cpp 2009-04-12 13:42:34 UTC (rev 2986) +++ branches/lucene2_3_2/src/shared/CLucene/util/StringBuffer.cpp 2009-04-12 17:12:31 UTC (rev 2987) @@ -40,7 +40,7 @@ len = 0; //Allocate a buffer of length bufferLength buffer = _CL_NEWARRAY(TCHAR,bufferLength); - bufferOwner = !consumeBuffer; + bufferOwner = consumeBuffer; } StringBuffer::StringBuffer(const TCHAR* value){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |