Memory leaks: Fixed false positive when allocated pointer is assigned
This commit is contained in:
parent
b8b16172b8
commit
92c5cffeb0
|
@ -235,7 +235,8 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Variable has already been allocated => error
|
// Variable has already been allocated => error
|
||||||
leakIfAllocated(tok, *varInfo);
|
if (conditionalAlloc.find(tok->varId()) == conditionalAlloc.end())
|
||||||
|
leakIfAllocated(tok, *varInfo);
|
||||||
varInfo->erase(tok->varId());
|
varInfo->erase(tok->varId());
|
||||||
|
|
||||||
// not a local variable nor argument?
|
// not a local variable nor argument?
|
||||||
|
|
|
@ -42,6 +42,7 @@ private:
|
||||||
TEST_CASE(assign7);
|
TEST_CASE(assign7);
|
||||||
TEST_CASE(assign8);
|
TEST_CASE(assign8);
|
||||||
TEST_CASE(assign9);
|
TEST_CASE(assign9);
|
||||||
|
TEST_CASE(assign10);
|
||||||
|
|
||||||
TEST_CASE(deallocuse1);
|
TEST_CASE(deallocuse1);
|
||||||
TEST_CASE(deallocuse2);
|
TEST_CASE(deallocuse2);
|
||||||
|
@ -179,6 +180,16 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
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() {
|
void deallocuse1() {
|
||||||
check("void f(char *p) {\n"
|
check("void f(char *p) {\n"
|
||||||
" free(p);\n"
|
" free(p);\n"
|
||||||
|
|
Loading…
Reference in New Issue