From 9d7defad2201c89ee7f65f245ec183a9dac1c59a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 29 Aug 2009 17:33:57 +0200 Subject: [PATCH] Fixed #615 (Memleak was detected in 1.32 but not in 1.33 and later) --- src/checkmemoryleak.cpp | 7 +++++++ test/testmemleak.cpp | 1 + 2 files changed, 8 insertions(+) diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 4af3466a3..86d566223 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -627,6 +627,13 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::liststr() == ";") addtoken(";"); + // var = strcpy|.. ( var , + if (Token::Match(tok, "[;{}] %varid% = memcpy|memmove|memset|strcpy|strncpy|strcat|strncat ( %varid% ,", varid)) + { + tok = tok->tokAt(4)->link(); + continue; + } + if (Token::Match(tok->previous(), "[(;{}] %varid% =", varid) || Token::Match(tok, "asprintf ( & %varid% ,", varid)) { diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 6da611d44..28c254854 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -366,6 +366,7 @@ private: // assign.. ASSERT_EQUALS(";;assign;", getcode("char *s; s = 0;", "s")); + ASSERT_EQUALS(";;;", getcode("char *s; s = strcpy(s, p);", "s")); // callfunc.. ASSERT_EQUALS(";;assign" "callfunc;", getcode("char *s; s = a();", "s"));