From 57ecdd693cdc4afea17e2dee9842c63f5bd0c738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 14 Dec 2013 07:37:24 +0100 Subject: [PATCH] Fixed #5149 (false positive: (error) Dereferencing 'memory' after it is deallocated / released) --- lib/checkmemoryleak.cpp | 2 ++ test/testmemleak.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 3947277f8..3c4e0e412 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -597,6 +597,8 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::liststrAt(1) == "=") return "assign"; + else if (tok->str()=="printf") + return "use"; // <- it is not certain printf dereference the pointer TODO: check the format string else return "use_"; } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 472309151..dc2835bb4 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2998,6 +2998,14 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + check("void f()\n" + "{\n" + " char *s = new char[100];\n" + " delete [] s;\n" + " printf(\"%p\\n\", s);\n" + "}"); + ASSERT_EQUALS("", errout.str()); + // The pointer to the pointer is valid.. check("void f()\n" "{\n"