public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/109120] New: False positive -Wanalyzer-malloc-leak with failed iconv_open()
@ 2023-03-14  5:37 urs at akk dot org
  2023-03-14 15:16 ` [Bug analyzer/109120] " dmalcolm at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: urs at akk dot org @ 2023-03-14  5:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109120

            Bug ID: 109120
           Summary: False positive -Wanalyzer-malloc-leak with failed
                    iconv_open()
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: urs at akk dot org
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu
            Target: x86_64-pc-linux-gnu
             Build: x86_64-pc-linux-gnu

Created attachment 54660
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54660&action=edit
minimal test case

gcc build from git @ a9835599fdb56f33da23e4514a9e21d8c2d51d71

with

configure --program-suffix=-13 --enable-languages=c,lto --enable-lto
--disable-multilib --enable-default-pie
make -j 12 BOOT_CFLAGS='-pipe -O0 -w' bootstrap

on

x86_64-pc-linux-gnu (AMD Ryzen 7 PRO 6850U); Debian GNU/Linux 12 (bookworm); 
Kernel 6.1.0-4-amd64; GLIBC 2.36-8

gcc-13 -v -save-temps -freport-bug -g -std=c11 -O0 -fanalyzer -c iconv.c -o
iconv

results in

iconv.c: In function ‘t’:
iconv.c:11:5: warning: leak of ‘cd’ [CWE-401] [-Wanalyzer-malloc-leak]
   11 |     return;
      |     ^~~~~~
  ‘t’: events 1-2
    |
    |    8 |     if ((cd = iconv_open("From", "To")) != (iconv_t) (-1)) {
    |      |        ~      ^~~~~~~~~~~~~~~~~~~~~~~~
    |      |        |      |
    |      |        |      (1) allocated here
    |      |        (2) following ‘false’ branch (when ‘cd ==
18446744073709551615’)...
    |
  ‘t’: event 3
    |
    |cc1:
    | (3): ...to here
    |
  ‘t’: event 4
    |
    |   11 |     return;
    |      |     ^~~~~~
    |      |     |
    |      |     (4) ‘cd’ leaks here; was allocated at (1)
    |

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

* [Bug analyzer/109120] False positive -Wanalyzer-malloc-leak with failed iconv_open()
  2023-03-14  5:37 [Bug analyzer/109120] New: False positive -Wanalyzer-malloc-leak with failed iconv_open() urs at akk dot org
@ 2023-03-14 15:16 ` dmalcolm at gcc dot gnu.org
  2023-03-14 16:11 ` dmalcolm at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2023-03-14 15:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109120

--- Comment #1 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
Thanks for filing this bug.  Seems to affect GCC 11 onwards, as GCC 10 didn't
support the 2nd argument to __attribute__((malloc)):

   Trunk: https://godbolt.org/z/MbWezaxrz
GCC 12.2: https://godbolt.org/z/vW1ae44Eb
GCC 11.3: https://godbolt.org/z/n9fzx8376

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

* [Bug analyzer/109120] False positive -Wanalyzer-malloc-leak with failed iconv_open()
  2023-03-14  5:37 [Bug analyzer/109120] New: False positive -Wanalyzer-malloc-leak with failed iconv_open() urs at akk dot org
  2023-03-14 15:16 ` [Bug analyzer/109120] " dmalcolm at gcc dot gnu.org
@ 2023-03-14 16:11 ` dmalcolm at gcc dot gnu.org
  2023-03-14 16:13 ` dmalcolm at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2023-03-14 16:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109120

--- Comment #2 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
Looks like the attribute was added to iconv_open in glibc in this commit:

https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=260a430dd841072020c4dae91468322e619e7330

Unfortunately, as currently written, the analyzer assumes that such
acquire/release pairs work on pointers, and, in particular, that NULL is the
failure value, rather than -1.

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

* [Bug analyzer/109120] False positive -Wanalyzer-malloc-leak with failed iconv_open()
  2023-03-14  5:37 [Bug analyzer/109120] New: False positive -Wanalyzer-malloc-leak with failed iconv_open() urs at akk dot org
  2023-03-14 15:16 ` [Bug analyzer/109120] " dmalcolm at gcc dot gnu.org
  2023-03-14 16:11 ` dmalcolm at gcc dot gnu.org
@ 2023-03-14 16:13 ` dmalcolm at gcc dot gnu.org
  2023-03-14 16:16 ` dmalcolm at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2023-03-14 16:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109120

--- Comment #3 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
(In reply to David Malcolm from comment #2)
> Looks like the attribute was added to iconv_open in glibc in this commit:
> 
> https://sourceware.org/git/?p=glibc.git;a=commitdiff;
> h=260a430dd841072020c4dae91468322e619e7330

Upstream glibc review of this patch was here:
  https://sourceware.org/pipermail/libc-alpha/2022-March/137040.html

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

* [Bug analyzer/109120] False positive -Wanalyzer-malloc-leak with failed iconv_open()
  2023-03-14  5:37 [Bug analyzer/109120] New: False positive -Wanalyzer-malloc-leak with failed iconv_open() urs at akk dot org
                   ` (2 preceding siblings ...)
  2023-03-14 16:13 ` dmalcolm at gcc dot gnu.org
@ 2023-03-14 16:16 ` dmalcolm at gcc dot gnu.org
  2023-03-14 16:31 ` [Bug analyzer/109120] False positive -Wanalyzer-malloc-leak with failed iconv_open() with glibc 2.36 onwards dmalcolm at gcc dot gnu.org
  2023-03-14 16:50 ` dmalcolm at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2023-03-14 16:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109120

--- Comment #4 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
...and thus presumably glibc 2.36 onwards uses the attribute on iconv_open.

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

* [Bug analyzer/109120] False positive -Wanalyzer-malloc-leak with failed iconv_open() with glibc 2.36 onwards
  2023-03-14  5:37 [Bug analyzer/109120] New: False positive -Wanalyzer-malloc-leak with failed iconv_open() urs at akk dot org
                   ` (3 preceding siblings ...)
  2023-03-14 16:16 ` dmalcolm at gcc dot gnu.org
@ 2023-03-14 16:31 ` dmalcolm at gcc dot gnu.org
  2023-03-14 16:50 ` dmalcolm at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2023-03-14 16:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109120

--- Comment #5 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
Potentially could be worked around from the gcc side by adding a known_function
implementation for iconv_{open,close}.

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

* [Bug analyzer/109120] False positive -Wanalyzer-malloc-leak with failed iconv_open() with glibc 2.36 onwards
  2023-03-14  5:37 [Bug analyzer/109120] New: False positive -Wanalyzer-malloc-leak with failed iconv_open() urs at akk dot org
                   ` (4 preceding siblings ...)
  2023-03-14 16:31 ` [Bug analyzer/109120] False positive -Wanalyzer-malloc-leak with failed iconv_open() with glibc 2.36 onwards dmalcolm at gcc dot gnu.org
@ 2023-03-14 16:50 ` dmalcolm at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2023-03-14 16:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109120

--- Comment #6 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
Note to self: there's a usage example in the glibc manual here:
  https://www.gnu.org/software/libc/manual/html_node/iconv-Examples.html

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

end of thread, other threads:[~2023-03-14 16:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-14  5:37 [Bug analyzer/109120] New: False positive -Wanalyzer-malloc-leak with failed iconv_open() urs at akk dot org
2023-03-14 15:16 ` [Bug analyzer/109120] " dmalcolm at gcc dot gnu.org
2023-03-14 16:11 ` dmalcolm at gcc dot gnu.org
2023-03-14 16:13 ` dmalcolm at gcc dot gnu.org
2023-03-14 16:16 ` dmalcolm at gcc dot gnu.org
2023-03-14 16:31 ` [Bug analyzer/109120] False positive -Wanalyzer-malloc-leak with failed iconv_open() with glibc 2.36 onwards dmalcolm at gcc dot gnu.org
2023-03-14 16:50 ` dmalcolm 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).