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

            Bug ID: 99044
           Summary: use-after-free false positive
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: antonio.chirizzi at gmail dot com
  Target Milestone: ---

Created attachment 50157
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50157&action=edit
Reproducer for the bug

Please find attached the reproducer for this use-after-free which looks a false
positive.

ls-tree-with-commit.c: In function ‘oid2strbuf_free’:
ls-tree-with-commit.c:53:17: warning: use after ‘free’ of ‘e_strbuf’ [CWE-416]
[-Wanalyzer-use-after-free]
   53 |                 strbuf_release(e_strbuf->value);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ‘oid2strbuf_free’: events 1-6
    |
    |   51 |         while ((e = hashmap_iter_next(&iter))) {
    |      |                ^
    |      |                |
    |      |                (1) following ‘true’ branch (when ‘e’ is
non-NULL)...
    |      |                (4) following ‘true’ branch (when ‘e’ is
non-NULL)...
    |   52 |                 struct oid2strbuf *e_strbuf = (struct oid2strbuf
*)e;
    |      |                                    ~~~~~~~~
    |      |                                    |
    |      |                                    (2) ...to here
    |      |                                    (5) ...to here
    |   53 |                 strbuf_release(e_strbuf->value);
    |      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |                 |
    |      |                 (6) use after ‘free’ of ‘e_strbuf’; freed at (3)
    |   54 |                 free(e_strbuf->value);
    |   55 |                 free(e);
    |      |                 ~~~~~~~
    |      |                 |
    |      |                 (3) freed here



use "gcc -fanalyzer -c ls-tree-with-commit.c"
  • [Bug analyzer/99044] New: u... antonio.chirizzi at gmail dot com via Gcc-bugs

Reply via email to