Skip to content

Commit 3e47acd

Browse files
Fix FP memleak (f'up to #12186) (#5671)
1 parent 4b9f3c6 commit 3e47acd

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

lib/checkleakautovar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ void CheckLeakAutoVar::functionCall(const Token *tokName, const Token *tokOpenin
971971
const Library::AllocFunc* deallocFunc = mSettings->library.getDeallocFuncInfo(tokName);
972972
VarInfo::AllocInfo dealloc(deallocFunc ? deallocFunc->groupId : 0, VarInfo::DEALLOC, tokName);
973973
if (const Library::AllocFunc* allocFunc = mSettings->library.getAllocFuncInfo(tokName)) {
974-
if (allocFunc->arg == argNr) {
974+
if (allocFunc->arg == argNr && !(arg->variable() && arg->variable()->isArgument() && arg->valueType() && arg->valueType()->pointer > 1)) {
975975
leakIfAllocated(arg, varInfo);
976976
VarInfo::AllocInfo& varAlloc = varInfo.alloctype[arg->varId()];
977977
varAlloc.type = allocFunc->groupId;

test/cfg/gnu.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ void memleak_asprintf(char **ptr, const char *fmt, const int arg)
355355
free(ptr);
356356
}
357357
if (-1 != asprintf(ptr,fmt,arg)) {}
358-
// cppcheck-suppress memleak
359358
}
360359

361360
void memleak_asprintf2() { // #12186
@@ -372,6 +371,15 @@ void memleak_asprintf3() {
372371
free(p);
373372
}
374373

374+
void memleak_asprintf4(char** p) {
375+
asprintf(p, "%s", "test");
376+
}
377+
378+
void memleak_asprintf5(char* p) {
379+
asprintf(&p, "%s", "test");
380+
// cppcheck-suppress memleak
381+
}
382+
375383
void memleak_xmalloc()
376384
{
377385
char *p = (char*)xmalloc(10);

0 commit comments

Comments
 (0)