public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/106473] New: -Wanalyzer-malloc-leak false positive regression when returning heap-allocation through nested pointers
@ 2022-07-29  7:13 raimue at codingfarm dot de
  2022-11-22 21:15 ` [Bug analyzer/106473] [12/13 Regression] " dmalcolm at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: raimue at codingfarm dot de @ 2022-07-29  7:13 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-11-28 22:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-29  7:13 [Bug analyzer/106473] New: -Wanalyzer-malloc-leak false positive regression when returning heap-allocation through nested pointers raimue at codingfarm dot de
2022-11-22 21:15 ` [Bug analyzer/106473] [12/13 Regression] " dmalcolm at gcc dot gnu.org
2022-11-24  1:46 ` cvs-commit at gcc dot gnu.org
2022-11-24  2:00 ` dmalcolm at gcc dot gnu.org
2022-11-28 22:46 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).