diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 5acce1028..87ff60dcd 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1036,6 +1036,12 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::listtokAt(2), varid) != No) + { + addtoken("dealloc"); + addtoken(";"); + } + else if (alloctype == Fd && varid) { if (Token::Match(tok, "while ( 0 <= %varid% )", varid) || diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index b8fa24109..71ee94f6a 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -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"));