From 27235f27aebfe799d15230444abf51c178a59070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 26 Oct 2010 17:49:48 +0200 Subject: [PATCH] Fixed #2129 (Invalid dereference after release report) --- lib/checkmemoryleak.cpp | 11 ++++++++++- test/testmemleak.cpp | 7 +++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index c5e7bd436..4a0e3c1c6 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -676,7 +676,16 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::listtokAt(2); tok2; tok2 = tok2->next()) + { + if (tok2->str() == "(" || tok2->str() == ")") + break; + if (tok2->varId() == varid) + return "use_"; + } + + return 0; } if (noreturn.find(tok->str()) != noreturn.end()) diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 0834dff15..f8293f5d2 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2280,6 +2280,13 @@ private: " strcpy(str, p);\n" "}\n"); ASSERT_EQUALS("[test.cpp:4]: (error) Dereferencing 'str' after it is deallocated / released\n", errout.str()); + + check("void foo(int x) {\n" + " char *str = malloc(10);\n" + " free(str);\n" + " assert(x);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); }