Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Brias
Copy link
Contributor

@Brias Brias commented Jun 25, 2025

Contribution description

#296 reports that with GCC 15 warnings for freeing non-heap objects are reported while compiling RTRlib.

I could reproduce the warnings when using a release build (-D CMAKE_BUILD_TYPE=Release) for the reported version as well as on master. However, the warnings are false positives since the correct pointers (i.e. the pointers that were returned by tommy_calloc/tommy_malloc) are passed to tommy_free.

A quick search online revealed that GCC can report false positives when the -Wfree-nonheap-object option is enabled (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54202).

To remove the warning and avoid further bug reports in the future I disabled the warning for the respective lines in the C code by using the following GCC pragma construct:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfree-nonheap-object"
		<lines-to-ignore>
#pragma GCC diagnostic pop

Testing procedure

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POLICY_VERSION_MINIMUM=3.5 ..
make # No `-Wfree-nonheap-object` warning is shown in the compilation output anymore

Issues/PRs references

Fixes #296

- GCC 15 (and maybe other versions) reports warnings in the `tommyds` library
  about freeing non-heap objects when compiling RTRlib without debug options
  (`-D CMAKE_BUILD_TYPE=Release`), even though the code is correct. A GCC bug
  report for false-positives when the `-Wfree-nonheap-object` option is enabled
  can be found in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54202.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QA: Compiler warnings ‘free’ called on pointer [-Wfree-nonheap-object]
2 participants