From 4094f6bc6e7f73819841725de44b8a4801f1fab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 4 May 2008 10:15:39 +0000 Subject: [PATCH] CheckMemoryLeak: Removed false positives --- CheckMemoryLeak.cpp | 5 +++++ tests.cpp | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CheckMemoryLeak.cpp b/CheckMemoryLeak.cpp index 562be7c24..0c183875b 100644 --- a/CheckMemoryLeak.cpp +++ b/CheckMemoryLeak.cpp @@ -210,6 +210,11 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[] if ( Match( tok, "[=,(] ( %type% %type% * ) %var1% [,);]", varnames ) ) return; + // Used. Todo: check if "p" is the first member in the struct. + // p = &var1->p; + if ( Match( tok, "= & %var1% . %var% ;", varnames ) ) + return; + // Linux lists.. if ( Match( tok, "%var% ( & %var1% .", varnames ) ) { diff --git a/tests.cpp b/tests.cpp index bb10e4cf2..54ea3a94a 100644 --- a/tests.cpp +++ b/tests.cpp @@ -637,10 +637,10 @@ static void memleak_in_function() " char *str = strdup(\"hello\");\n" " char *str2 = (char *)str;\n" " free(str2);\n" - "}\n"; + "}\n"; check( CheckMemoryLeak, __LINE__, test17, "" ); - + const char test18[] = "static void f()\n" "{\n" " char *str;\n" @@ -650,6 +650,20 @@ static void memleak_in_function() "}\n"; check( CheckMemoryLeak, __LINE__, test18, "" ); + + const char test19[] = "struct abc\n" + "{\n" + " int a;\n" + " int b;\n" + " int c;\n" + "}\n" + "\n" + "static void f()\n" + "{\n" + " struct abc *abc1 = new abc;\n" + " p = &abc1->a;\n" + "}\n"; + check( CheckMemoryLeak, __LINE__, test19, "" ); } //---------------------------------------------------------------------------