cmajor icon indicating copy to clipboard operation
cmajor copied to clipboard

Use after free errors while compiling with gcc 14.1.1 on Fedora 40

Open ycollet opened this issue 1 year ago • 4 comments

I am trying to build cmajor for Fedora 40 and I've got a lot of "use after free" errors while compiling with gcc 14.1.1. Here is an example:

In member function ‘std::set<void*, std::less<void*>, std::allocator<void*> >::erase(void* const&)’,
    inlined from ‘GraphViz::GraphVizFree(void*)’ at /home/collette/rpmbuild/BUILD/cmajor/3rdParty/graphviz/cmaj_GraphViz.cpp:72:23,
    inlined from ‘GraphViz::gvFreeRenderData(char*)’ at /home/collette/rpmbuild/BUILD/cmajor/3rdParty/graphviz/./gvc/gvc.c:223:10,
    inlined from ‘convertDOTtoSVG(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)’ at /home/collette/rpmbuild/BUILD/cmajor/3rdParty/graphviz/cmaj_GraphViz.cpp:316:22:
/usr/include/c++/14/bits/stl_set.h:687:26: warning: pointer used after ‘free’ [-Wuse-after-free]
  687 |       { return _M_t.erase(__x); }
      |                ~~~~~~~~~~^~~~~

I added "-Wno-error=use-after-free" to the list of CXXFLAGS to workaround this problem.

ycollet avatar Jul 27 '24 18:07 ycollet

Thanks. It sounds like we need to add something to choc 'choc_DisableAllWarnings'. We have the strategy of trying to use external libraries as they are without 'fixing' them. Obviously we try and upstream changes, but for stuff like this the 'disable all warnings when compiling this unit' approach is pragmatic.

I'll look at getting a newer gcc build going and investigate this further.

cesaref avatar Jul 27 '24 18:07 cesaref

Thanks a lot for your quick answer. With my workaround, the build works. I will try the plugin soon.

ycollet avatar Jul 27 '24 18:07 ycollet

I try to package cmajor for Fedora. Some compilation flags are added to CMAKE_CXX_FLAGS:

-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer

ycollet avatar Jul 27 '24 18:07 ycollet

Sorry, had a few other bits on but got around to trying this out. Can you try the latest release and see if i've resolved your warnings?

cesaref avatar Aug 01 '24 17:08 cesaref

I'll assume the updates have resolved this. If not, feel free to re-open and i'll look again!

cesaref avatar Sep 24 '24 16:09 cesaref