https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106473
Bug ID: 106473 Summary: -Wanalyzer-malloc-leak false positive regression when returning heap-allocation through nested pointers Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: analyzer Assignee: dmalcolm at gcc dot gnu.org Reporter: raimue at codingfarm dot de Target Milestone: --- Source: void foo(char **args[], int *argc) { *argc = 1; (*args)[0] = __builtin_malloc(42); } Compiler output: $ gcc-12 -Wall -fanalyzer -c -o foo.o foo.c foo.c: In function 'foo': foo.c:4:1: warning: leak of '<unknown>' [CWE-401] [-Wanalyzer-malloc-leak] 4 | } | ^ 'foo': events 1-2 | | 3 | (*args)[0] = __builtin_malloc(42); | | ^~~~~~~~~~~~~~~~~~~~ | | | | | (1) allocated here | 4 | } | | ~ | | | | | (2) '<unknown>' leaks here; was allocated at (1) | Notes: This is only reported with the write to argc happening first, which should be considered completely unrelated to args. Reordering the two statements resolves the analyzer report. Tested versions: gcc 10.3: FAIL gcc 11.2: OK gcc 12.0: FAIL I therefore consider this a regression as it was not reported by gcc 11. Compiler Explorer link: https://gcc.godbolt.org/z/zGanPa3fs