From 474fed453e3619c6cf13e15468f71f779c2a05dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 18 Aug 2019 19:45:39 +0200 Subject: [PATCH] memleak: Fixed false negative for sample --- lib/checkleakautovar.cpp | 2 +- samples/memleak/out.txt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index a4608bde4..c12011c92 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -735,7 +735,7 @@ const Token * CheckLeakAutoVar::checkTokenInsideExpression(const Token * const t deallocUseError(tok, tok->str()); } else if (Token::simpleMatch(tok->tokAt(-2), "= &")) { varInfo->erase(tok->varId()); - } else if (tok->strAt(-1) == "=") { + } else if (Token::Match(tok->previous(), "= %var% [;,)]")) { varInfo->erase(tok->varId()); } } else if (Token::Match(tok->previous(), "& %name% = %var% ;")) { diff --git a/samples/memleak/out.txt b/samples/memleak/out.txt index e69de29bb..263ac1b1a 100644 --- a/samples/memleak/out.txt +++ b/samples/memleak/out.txt @@ -0,0 +1,3 @@ +samples/memleak/bad.c:8:5: error: Memory leak: a [memleak] + return result; + ^