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

            Bug ID: 116900
           Summary: False Positive Use After Free Warning
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alpha.and.omega.programmer at gmail dot com
  Target Milestone: ---

Created attachment 59230
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59230&action=edit
Bug Demonstration

$ gcc -Wuse-after-free t.c
t.c: In function 'main':
t.c:7:9: warning: pointer 'ptr' used after 'free' [-Wuse-after-free]
    7 |         printf("%p\n", ptr);
      |         ^~~~~~~~~~~~~~~~~~~
t.c:6:9: note: call to 'free' here
    6 |         free(ptr);
      |         ^~~~~~~~~


After mallocing and freeing a pointer, attempting the print the memory address
held in the pointer without attempting to dereference the pointer, such as with
printf("%p"), causes a use after free warning.

The pointer is invalid, but since no attempt is made to dereference the
pointer, no use after free is possible, so this warning is a false positive.
This happens with any pointer type, including a void pointer which can't
possibly be dereferenced.
  • [Bug c/116900] Ne... alpha.and.omega.programmer at gmail dot com via Gcc-bugs

Reply via email to