Fix FP memleak with array (#4133)

* Fix #11019 FN memleak with redundant pointer op

* Style

* Fix #7705 FN: Memory leak not detected on struct member

* Fix FP memleak with function call, fix cppcheckError

* Fix FP memleak with array
This commit is contained in:
chrchr-github 2022-05-26 00:03:30 +02:00 committed by GitHub
parent 2b611709e2
commit 86763b7b0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -795,7 +795,7 @@ void CheckMemoryLeakStructMember::checkStructVariable(const Variable * const var
return {}; return {};
const Token* top = varTok; const Token* top = varTok;
while (top->astParent()) { while (top->astParent()) {
if (top->astParent()->str() == "(") if (Token::Match(top->astParent(), "(|["))
return {}; return {};
top = top->astParent(); top = top->astParent();
} }

View File

@ -1922,6 +1922,14 @@ private:
" sess->fp = popen(cmd, rcmd == RSH_PIPE_READ ? \"r\" : \"w\");\n" " sess->fp = popen(cmd, rcmd == RSH_PIPE_READ ? \"r\" : \"w\");\n"
"}\n", false); "}\n", false);
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("struct S { char* a[2]; };\n"
"enum E { E0, E1 };\n"
"void f(struct S* s, enum E e, const char* n) {\n"
" free(s->a[e]);\n"
" s->a[e] = strdup(n);\n"
"}\n", false);
ASSERT_EQUALS("", errout.str());
} }
void failedAllocation() { void failedAllocation() {