https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97072
Bug ID: 97072
Summary: -Wanalyzer-malloc-leak false positive when writing
through some pointers
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: analyzer
Assignee: dmalcolm at gcc dot gnu.org
Reporter: dmalcolm at gcc dot gnu.org
Target Milestone: ---
Initially seen when writing through an unknown_svalue pointer; this reproducer
captures similar behavior, albeit with a conjured_svalue pointer:
#include <stdlib.h>
void unknown_fn_1 (void *);
void test_1 (int co, int y)
{
void *p = malloc (1024);
void **q;
unknown_fn_1 (&q);
*q = p;
}
t.c: In function ‘test_1’:
t.c:11:1: warning: leak of ‘p’ [CWE-401] [-Wanalyzer-malloc-leak]
11 | }
| ^
‘test_1’: events 1-2
|
| 7 | void *p = malloc (1024);
| | ^~~~~~~~~~~~~
| | |
| | (1) allocated here
|......
| 11 | }
| | ~
| | |
| | (2) ‘p’ leaks here; was allocated at (1)
|
https://godbolt.org/z/WcMWda
The leak warning is a false positive, as p was written to *q.