From 3205775eb90f454643ef70ceabfdd3f892f0dc47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 30 Jun 2010 09:21:15 +0200 Subject: [PATCH] Fixed #1790 (mismatching allocation/deallocation false positive) --- lib/checkmemoryleak.cpp | 1 + test/testmemleak.cpp | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index ed7b264e8..d3fbfab8e 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -694,6 +694,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::listtokAt(-3), "[;{}] %varid% = %var% (", varid)) { const Token *ftok = _tokenizer->getFunctionTokenByName(funcname.c_str()); AllocType a = functionReturnType(ftok); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index fc7b3acae..3441c864d 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -298,6 +298,7 @@ private: TEST_CASE(allocfunc3); TEST_CASE(allocfunc4); TEST_CASE(allocfunc5); + TEST_CASE(allocfunc6); TEST_CASE(throw1); TEST_CASE(throw2); @@ -1808,10 +1809,28 @@ private: " free(tmp);\n" "}\n"); TODO_ASSERT_EQUALS(std::string(""), errout.str()); - } + void allocfunc6() + { + check("static FILE* data()\n" + "{\n" + " return fopen(\"data.txt\",\"rt\");\n" + "}\n" + "\n" + "static void foo()\n" + "{\n" + " char* expr;\n" + " func(&expr);\n" + "\n" + " FILE *f = data();\n" + " fclose(f);\n" + "\n" + " free(expr);\n" + "}\n"); + ASSERT_EQUALS(std::string(""), errout.str()); + }