Fixed #1716 (Wrong reporting of leak with close() in a while loop condition)

This commit is contained in:
Daniel Marjamäki 2010-05-29 21:11:59 +02:00
parent 24703418bd
commit 495dfde32c
2 changed files with 7 additions and 0 deletions

View File

@ -1036,6 +1036,12 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
continue;
}
else if (varid && getDeallocationType(tok->tokAt(2), varid) != No)
{
addtoken("dealloc");
addtoken(";");
}
else if (alloctype == Fd && varid)
{
if (Token::Match(tok, "while ( 0 <= %varid% )", varid) ||

View File

@ -522,6 +522,7 @@ private:
// open/close
ASSERT_EQUALS(";;alloc;if(var){dealloc;}", getcode("int f; f=open(); if(f>=0)close(f);", "f"));
ASSERT_EQUALS(";;alloc;ifv{;}", getcode("int f; f=open(); if(f!=-1 || x);", "f"));
ASSERT_EQUALS(";;;dealloc;loop{}}", getcode(";int f; while (close(f) == -1) { } }", "f"));
ASSERT_EQUALS(";;dealloc;", getcode("int f; e |= fclose(f);", "f"));