https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98753
--- Comment #16 from Stefan Krah <stefan at bytereef dot org> --- I have encountered the same issue (gcc emits a false positive warning when free() is called conditionally) in the mpdecimal project when compiled with -flto. Worse, mpdecimal itself as well as a large test suite compile without warnings, so distributions will think everything is fine. Until a user uses the static libmpdec.a for a trivial program: wget https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-2.5.1.tar.gz tar xvf mpdecimal-2.5.1.tar.gz cd mpdecimal-2.5.1 ./configure CFLAGS="-flto=auto" CXXFLAGS="-flto=auto" LDFLAGS="-flto=auto" LDXXFLAGS="-flto=auto" make # The trivial program: $ cd libmpdec $ make bench gcc -Wall -Wextra -Wno-unknown-pragmas -std=c99 -pedantic -DNDEBUG -O2 -flto=auto -o bench bench.c libmpdec.a -lm In function ‘mpd_del’, inlined from ‘_mpd_qaddsub.constprop’ at mpdecimal.c:3471:5: mpdecimal.c:470:9: warning: attempt to free a non-heap object ‘big_aligned’ [-Wfree-nonheap-object] mpd_free(dec); Here, the user will get a static library to which he may not even have the source code readily available and gets a false positive warning for code in that library. Like others, I think this warning should be under a category -Wmaybe and be less decisive in its message. For the next mpdecimal release the Makefile will filter out -flto for the static library build.