From b3fef7957a77e594562956f78d8c9c105b13a8ad Mon Sep 17 00:00:00 2001 From: rikardfalkeborn Date: Mon, 1 Oct 2018 11:58:27 +0200 Subject: [PATCH] Fix FP with fclose after comma (#7525) (#1407) --- lib/checkmemoryleak.cpp | 2 +- test/testmemleak.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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"