public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/94399] New: analyzer reports false positives for stuff freed using  __attribute__((cleanup()))
@ 2020-03-30  9:24 zbyszek at in dot waw.pl
  2020-08-13 20:28 ` [Bug analyzer/94399] " dmalcolm at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: zbyszek at in dot waw.pl @ 2020-03-30  9:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94399
           Summary: analyzer reports false positives for stuff freed using
                     __attribute__((cleanup()))
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zbyszek at in dot waw.pl
  Target Milestone: ---

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

$ rpm -q gcc
gcc-10.0.1-0.9.fc32.x86_64

$ cat testfree.c
#include <stdlib.h>

#define _cleanup_(f) __attribute__((cleanup(f)))

static inline void freep(void **p) {
        free(*p);
}

void test(void) {
        _cleanup_(freep) void *ptr;

        ptr = malloc(3);
}

int main(void) {
        test();
        return 0;
}

$ gcc -fanalyzer testfree.c -o testfree
testfree.c: In function ‘test’:
testfree.c:13:1: warning: leak of ‘ptr’ [CWE-401] [-Wanalyzer-malloc-leak]
   13 | }
      | ^
  ‘test’: events 1-4
    |
    |    9 | void test(void) {
    |      |      ^~~~
    |      |      |
    |      |      (1) entry to ‘test’
    |   10 |         _cleanup_(freep) void *ptr;
    |      |                                ~~~
    |      |                                |
    |      |                                (4) calling ‘freep’ from ‘test’
    |   11 | 
    |   12 |         ptr = malloc(3);
    |      |         ~~~~~~~~~~~~~~~
    |      |             | |
    |      |             | (2) allocated here
    |      |             (3) allocated here
    |
    +--> ‘freep’: events 5-6
           |
           |    5 | static inline void freep(void **p) {
           |      |                    ^~~~~
           |      |                    |
           |      |                    (5) entry to ‘freep’
           |    6 |         free(*p);
           |      |         ~~~~~~~~    
           |      |         |
           |      |         (6) state of ‘ptr’: ‘start’ -> ‘freed’ (origin:
NULL)
           |
    <------+
    |
  ‘test’: events 7-8
    |
    |   10 |         _cleanup_(freep) void *ptr;
    |      |                                ^~~
    |      |                                |
    |      |                                (7) returning to ‘test’ from
‘freep’
    |......
    |   13 | }
    |      | ~                               
    |      | |
    |      | (8) ‘ptr’ leaks here; was allocated at (3)
    |



It seems that the analyzer knows that the pointer was freed (event 6), but then
still reports a leak (8).

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

* [Bug analyzer/94399] analyzer reports false positives for stuff freed using  __attribute__((cleanup()))
  2020-03-30  9:24 [Bug c/94399] New: analyzer reports false positives for stuff freed using __attribute__((cleanup())) zbyszek at in dot waw.pl
@ 2020-08-13 20:28 ` dmalcolm at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2020-08-13 20:28 UTC (permalink / raw)
  To: gcc-bugs

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

David Malcolm <dmalcolm at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
                 CC|                            |dmalcolm at gcc dot gnu.org
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
The leak false positive should be fixed by
g:808f4dfeb3a95f50f15e71148e5c1067f90a126d (for GCC 11).  Marking this as
fixed.

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

end of thread, other threads:[~2020-08-13 20:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-30  9:24 [Bug c/94399] New: analyzer reports false positives for stuff freed using __attribute__((cleanup())) zbyszek at in dot waw.pl
2020-08-13 20:28 ` [Bug analyzer/94399] " 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).