Description of problem: gcc-12.0.1 is reporting suspicious warning/error about the use-after-free when compiling libdatovka (without the gcc-12 fix patch). Version-Release number of selected component (if applicable): gcc-12.0.1-0.2.fc36 How reproducible: Always Steps to Reproduce: 1. git clone https://src.fedoraproject.org/rpms/libdatovka.git 2. cd libdatovka 3. git checkout 13bb00d9ca07713c403dee9924a1de87c3accebe 4. fedpkg --release f36 build Actual results: isds.c: In function 'build_send_check_dbdummy_request.part.0.constprop.0': isds.c:6101:5: error: pointer 'request_37' used after 'free' [-Werror=use-after-free] 6101 | xmlFreeNode(request); | ^~~~~~~~~~~~~~~~~~~~ isds.c:6100:5: note: call to 'free' here 6100 | free(service_name_locale); | ^~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors Expected results: No warning/error Additional info: Upstream cannot spot any problem with the code, upstream ticket: https://gitlab.nic.cz/datovka/libdatovka/-/issues/17
The same problem with the gcc-12.0.1-0.3.fc36
I looked at the code and I think this is a bug in GCC. Here is a standalone reproducer: /* gcc -O1 -pipe -Wuse-after-free=1 -Werror -c test.c -o /dev/null */ #include <stdlib.h> void *make(void); void barf(void *); void function(void) { void *cat = NULL; void *dog = NULL; cat = make(); if (!cat) goto leave; dog = make(); leave: free(cat); barf(dog); } $ gcc -O1 -pipe -Wuse-after-free=1 -Werror -c test.c -o /dev/null test.c: In function ‘function’: test.c:19:5: error: pointer ‘dog’ used after ‘free’ [-Werror=use-after-free] 19 | barf(dog); | ^~~~~~~~~ test.c:18:5: note: call to ‘free’ here 18 | free(cat); | ^~~~~~~~~ cc1: all warnings being treated as errors A trigger is the free() call. Negating the (!cat) condition, making the goto unconditional, or removing the dog = make() assignment disappears the warning. I silenced this warning in libisds with <https://repo.or.cz/libisds.git/patch/e61d1504456b80121837acb23549bf630c0a19df> where I escape the function before attempting to call free() on the NULL pointer.
After applying the patch, I got a similar failure elsewhere, but only on s390x and ppc64le <https://koji.fedoraproject.org/koji/taskinfo?taskID=82173494>.
The architecture-specific issue resolved with this libisds patch <https://repo.or.cz/libisds.git/patch/890d63b43a6aac9f9f5bd83c01f2423aa661c716>.
The false positive for the test case in comment #2 is tracked in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104232. The fix for that was committed earlier today. If that doesn't also resolve the originally reported problem please attach a preprocessing translation unit for the file (the result of compiling with -E).
This bug appears to have been reported against 'rawhide' during the Fedora 36 development cycle. Changing version to 36.
This message is a reminder that Fedora Linux 36 is nearing its end of life. Fedora will stop maintaining and issuing updates for Fedora Linux 36 on 2023-05-16. It is Fedora's policy to close all bug reports from releases that are no longer maintained. At that time this bug will be closed as EOL if it remains open with a 'version' of '36'. Package Maintainer: If you wish for this bug to remain open because you plan to fix it in a currently maintained version, change the 'version' to a later Fedora Linux version. Note that the version field may be hidden. Click the "Show advanced fields" button if you do not see it. Thank you for reporting this issue and we are sorry that we were not able to fix it before Fedora Linux 36 is end of life. If you would still like to see this bug fixed and are able to reproduce it against a later version of Fedora Linux, you are encouraged to change the 'version' to a later version prior to this bug being closed.
Fedora Linux 36 entered end-of-life (EOL) status on 2023-05-16. Fedora Linux 36 is no longer maintained, which means that it will not receive any further security or bug fix updates. As a result we are closing this bug. If you can reproduce this bug against a currently maintained version of Fedora Linux please feel free to reopen this bug against that version. Note that the version field may be hidden. Click the "Show advanced fields" button if you do not see the version field. If you are unable to reopen this bug, please file a new report against an active release. Thank you for reporting this bug and we are sorry it could not be fixed.