Memory leaks: Fixed false positive when allocated pointer is assigned

This commit is contained in:
Daniel Marjamäki 2012-05-26 21:28:35 +02:00
parent b8b16172b8
commit 92c5cffeb0
2 changed files with 13 additions and 1 deletions

View File

@ -235,7 +235,8 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
continue;
// Variable has already been allocated => error
leakIfAllocated(tok, *varInfo);
if (conditionalAlloc.find(tok->varId()) == conditionalAlloc.end())
leakIfAllocated(tok, *varInfo);
varInfo->erase(tok->varId());
// not a local variable nor argument?

View File

@ -42,6 +42,7 @@ private:
TEST_CASE(assign7);
TEST_CASE(assign8);
TEST_CASE(assign9);
TEST_CASE(assign10);
TEST_CASE(deallocuse1);
TEST_CASE(deallocuse2);
@ -179,6 +180,16 @@ private:
ASSERT_EQUALS("", errout.str());
}
void assign10() {
check("void foo() {\n"
" char *p;\n"
" if (x) { p = malloc(10); }\n"
" if (!x) { p = NULL; }\n"
" free(p);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void deallocuse1() {
check("void f(char *p) {\n"
" free(p);\n"