cmListFileLexer: Fix leak on error before EOF

Teach cmListFileLexerDestroy to call cmListFileLexerSetToken with a NULL
token to free the token string buffer.  Without this, if an error occurs
before the token cleanup happens when EOF is reached, then the token
string buffer may leak.
This commit is contained in:
Brad King 2013-09-17 10:24:17 -04:00
parent 40c76c1dc8
commit ad3d5c59b3
2 changed files with 2 additions and 0 deletions

View File

@ -2271,6 +2271,7 @@ static void cmListFileLexerInit(cmListFileLexer* lexer)
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
static void cmListFileLexerDestroy(cmListFileLexer* lexer) static void cmListFileLexerDestroy(cmListFileLexer* lexer)
{ {
cmListFileLexerSetToken(lexer, 0, 0);
if(lexer->file || lexer->string_buffer) if(lexer->file || lexer->string_buffer)
{ {
cmListFileLexer_yylex_destroy(lexer->scanner); cmListFileLexer_yylex_destroy(lexer->scanner);

View File

@ -292,6 +292,7 @@ static void cmListFileLexerInit(cmListFileLexer* lexer)
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
static void cmListFileLexerDestroy(cmListFileLexer* lexer) static void cmListFileLexerDestroy(cmListFileLexer* lexer)
{ {
cmListFileLexerSetToken(lexer, 0, 0);
if(lexer->file || lexer->string_buffer) if(lexer->file || lexer->string_buffer)
{ {
cmListFileLexer_yylex_destroy(lexer->scanner); cmListFileLexer_yylex_destroy(lexer->scanner);