Skip to content

Commit

Permalink
Fix #12498 FP memleak with getline() and array (#6108)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Mar 10, 2024
1 parent 343b749 commit 866619c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cfg/posix.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5237,7 +5237,7 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
<arg nr="2" direction="inout">
<not-null/>
</arg>
<arg nr="3" direction="in">
<arg nr="3" direction="inout">
<not-null/>
<not-uninit/>
</arg>
Expand Down
3 changes: 2 additions & 1 deletion lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,8 @@ void CheckLeakAutoVar::functionCall(const Token *tokName, const Token *tokOpenin
while (Token::Match(arg, "%name% .|:: %name%"))
arg = arg->tokAt(2);

if (Token::Match(arg, "%var% [-,)] !!.") || Token::Match(arg, "& %var% !!.")) {
if ((Token::Match(arg, "%var% [-,)] !!.") && !(arg->variable() && arg->variable()->isArray())) ||
(Token::Match(arg, "& %var% !!.") && !(arg->next()->variable() && arg->next()->variable()->isArray()))) {
// goto variable
const bool isAddressOf = arg->str() == "&";
if (isAddressOf)
Expand Down
9 changes: 9 additions & 0 deletions test/cfg/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,15 @@ void memleak_getline() { // #11043
line = NULL;
}

void memleak_getline_array(FILE* stream) { // #12498
char* a[2] = { 0 };
size_t n;
getline(&a[0], &n, stream);
getline(&a[1], &n, stream);
free(a[0]);
free(a[1]);
}

void * identicalCondition_mmap(int fd, size_t size) // #9940
{
void* buffer = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
Expand Down

0 comments on commit 866619c

Please sign in to comment.