diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index dc136b8c3..a5731e157 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -919,7 +919,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::listprevious(), "%op%|;|{|}|) ::| %name%") || (Token::Match(tok->previous(), "( ::| %name%") && (!rettail || rettail->str() != "loop"))) { + if (Token::Match(tok->previous(), "%op%|;|,|{|}|) ::| %name%") || (Token::Match(tok->previous(), "( ::| %name%") && (!rettail || rettail->str() != "loop"))) { if (tok->str() == "::") tok = tok->next(); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 347c571e7..73b2dcaac 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -347,6 +347,7 @@ private: TEST_CASE(creat_function); TEST_CASE(close_function); TEST_CASE(fd_functions); + TEST_CASE(fclose_comma); // #7525 TEST_CASE(pointer_to_pointer); TEST_CASE(dealloc_and_alloc_in_func); @@ -3816,6 +3817,16 @@ private: } } + void fclose_comma() { + check("int main(void) {\n" + " const char *const outfile = \"out.txt\";\n" + " FILE *f;\n" + " f = fopen(outfile, \"w\");\n" + " fprintf(f, \"foo\\n\"), fclose(f);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void pointer_to_pointer() { check("void f(char **data)\n" "{\n"