Skip to content

Commit 866619c

Browse files
Fix #12498 FP memleak with getline() and array (#6108)
1 parent 343b749 commit 866619c

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

cfg/posix.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5237,7 +5237,7 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
52375237
<arg nr="2" direction="inout">
52385238
<not-null/>
52395239
</arg>
5240-
<arg nr="3" direction="in">
5240+
<arg nr="3" direction="inout">
52415241
<not-null/>
52425242
<not-uninit/>
52435243
</arg>

lib/checkleakautovar.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,8 @@ void CheckLeakAutoVar::functionCall(const Token *tokName, const Token *tokOpenin
985985
while (Token::Match(arg, "%name% .|:: %name%"))
986986
arg = arg->tokAt(2);
987987

988-
if (Token::Match(arg, "%var% [-,)] !!.") || Token::Match(arg, "& %var% !!.")) {
988+
if ((Token::Match(arg, "%var% [-,)] !!.") && !(arg->variable() && arg->variable()->isArray())) ||
989+
(Token::Match(arg, "& %var% !!.") && !(arg->next()->variable() && arg->next()->variable()->isArray()))) {
989990
// goto variable
990991
const bool isAddressOf = arg->str() == "&";
991992
if (isAddressOf)

test/cfg/posix.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,15 @@ void memleak_getline() { // #11043
10701070
line = NULL;
10711071
}
10721072

1073+
void memleak_getline_array(FILE* stream) { // #12498
1074+
char* a[2] = { 0 };
1075+
size_t n;
1076+
getline(&a[0], &n, stream);
1077+
getline(&a[1], &n, stream);
1078+
free(a[0]);
1079+
free(a[1]);
1080+
}
1081+
10731082
void * identicalCondition_mmap(int fd, size_t size) // #9940
10741083
{
10751084
void* buffer = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);

0 commit comments

Comments
 (0)