Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-Werror=free-nonheap-object in allocators.h line 271 #2267

Open
djbn65 opened this issue Mar 21, 2024 · 0 comments · May be fixed by #2268
Open

-Werror=free-nonheap-object in allocators.h line 271 #2267

djbn65 opened this issue Mar 21, 2024 · 0 comments · May be fixed by #2268

Comments

@djbn65
Copy link
Contributor

djbn65 commented Mar 21, 2024

This error comes from schematest.cpp line 129:

char jsonBuffer[65536];
MemoryPoolAllocator<> jsonAllocator(jsonBuffer, sizeof(jsonBuffer));

The destructor for MemoryPoolAllocator does the following:

if (shared_->ownBuffer) {
    baseAllocator_->Free(shared_);
}

When building with GNU 11.4.0 as identified by cmake, this emits -Werror=free-nonheap-object:

[ 98%] Building CXX object test/perftest/CMakeFiles/perftest.dir/schematest.cpp.o
In file included from /grmn/prj/fit/mon/FOC/external/rapidjson/include/rapidjson/document.h:20,
                 from /grmn/prj/fit/mon/FOC/external/rapidjson/include/rapidjson/schema.h:18,
                 from /grmn/prj/fit/mon/FOC/external/rapidjson/test/perftest/schematest.cpp:5:
In static member function ‘static void rapidjson::CrtAllocator::Free(void*)’,
    inlined from ‘rapidjson::MemoryPoolAllocator<BaseAllocator>::~MemoryPoolAllocator() [with BaseAllocator = rapidjson::CrtAllocator]’ at /grmn/prj/fit/mon/FOC/external/rapidjson/include/rapidjson/allocators.h:271:33,
    inlined from ‘rapidjson::MemoryPoolAllocator<BaseAllocator>::~MemoryPoolAllocator() [with BaseAllocator = rapidjson::CrtAllocator]’ at /grmn/prj/fit/mon/FOC/external/rapidjson/include/rapidjson/allocators.h:259:5,
    inlined from ‘virtual void Schema::SetUp()’ at /grmn/prj/fit/mon/FOC/external/rapidjson/test/perftest/schematest.cpp:129:5:
/grmn/prj/fit/mon/FOC/external/rapidjson/include/rapidjson/rapidjson.h:715:38: error: ‘void free(void*)’ called on unallocated object ‘jsonBuffer’ [-Werror=free-nonheap-object]
  715 | #define RAPIDJSON_FREE(ptr) std::free(ptr)
      |                             ~~~~~~~~~^~~~~
/grmn/prj/fit/mon/FOC/external/rapidjson/include/rapidjson/allocators.h:100:54: note: in expansion of macro ‘RAPIDJSON_FREE’
  100 |     static void Free(void *ptr) RAPIDJSON_NOEXCEPT { RAPIDJSON_FREE(ptr); }
      |                                                      ^~~~~~~~~~~~~~
/grmn/prj/fit/mon/FOC/external/rapidjson/test/perftest/schematest.cpp: In member function ‘virtual void Schema::SetUp()’:
/grmn/prj/fit/mon/FOC/external/rapidjson/test/perftest/schematest.cpp:90:14: note: declared here
   90 |         char jsonBuffer[65536];
      |              ^~~~~~~~~~
cc1plus: all warnings being treated as errors

This can be fixed by changing that block to:
baseAllocator_->Free(shared_->ownBuffer ? shared_ : nullptr);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant