I hope this helps ease your headache of getting and freeing heap pointers, file descriptors, etc, before exit.
Too bad there's no RAII, but we do have atexit(). Thanks for that at least...
Include <xcleanup.h> in your project. An example of use can be found in the main.c. Build with clang/gcc.
To build an example (unix), type:
mkdir .build
cd .build
cmake ..
cmake --build .
On Windows, for example, you can use nmake:
mkdir .build
cd .build
cmake .. -G"NMake Makefiles" -DCMAKE_C_COMPILER=clang
nmake
To leak-check (unix), type:
cmake --build . --target leak-check