Build fails on -Werror=use-after-free on GCC 12.2.0
mmtj opened this issue · 1 comments
mmtj commented
While trying to build test tools
$ mkdir build
$ cd build/
$ cmake ..
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Deprecation Warning at src/CMakeLists.txt:1 (cmake_minimum_required):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mmtj/devel/DAWN/build
I bumped into following error:
$ make
[ 4%] Building C object src/CMakeFiles/dawn.dir/main.c.o
[ 8%] Building C object src/CMakeFiles/dawn.dir/storage/datastorage.c.o
In file included from /home/mmtj/devel/DAWN/src/storage/datastorage.c:4:
/home/mmtj/devel/DAWN/src/storage/datastorage.c: In function ‘insert_macs_from_file’:
/home/mmtj/devel/DAWN/src/include/memory_utils.h:25:26: error: pointer ‘fp’ used after ‘fclose’ [-Werror=use-after-free]
25 | #define dawn_unregmem(p) dawn_memory_unregister(DAWN_MEMUNREG, __FILE__, __LINE__, p)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/mmtj/devel/DAWN/src/storage/datastorage.c:1336:5: note: in expansion of macro ‘dawn_unregmem’
1336 | dawn_unregmem(fp);
| ^~~~~~~~~~~~~
/home/mmtj/devel/DAWN/src/storage/datastorage.c:1335:5: note: call to ‘fclose’ here
1335 | fclose(fp);
| ^~~~~~~~~~
At top level:
cc1: note: unrecognized command-line option ‘-Wno-unknown-warning-option’ may have been intended to silence earlier diagnostics
cc1: all warnings being treated as errors
make[2]: *** [src/CMakeFiles/dawn.dir/build.make:90: src/CMakeFiles/dawn.dir/storage/datastorage.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:102: src/CMakeFiles/dawn.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
Looking into the src/storage/datastorage.c:1336
, there indeed seems to be use-after-free:
void insert_macs_from_file() {
FILE *fp;
// more code in between...
fclose(fp);
dawn_unregmem(fp);