If you are serious about protecting your application from heap-related attacks, such as heap overflow, use-after-free, or double free, you may consider replacing your standard memory allocator with a security-oriented version. Two projects that may be of interest are as follows:
- FreeGuard, available at https://github.com/UTSASRG/FreeGuard and described in a paper at https://arxiv.org/abs/1709.02746
- hardened_malloc from the GrapheneOS project, available at https://github.com/GrapheneOS/hardened_malloc
FreeGuard was released in 2017 and it hasn't seen much change since then other than sporadic bug fixes. hardened_malloc, on the other hand, is actively developed. Both allocators are designed to act as drop-in replacements for the standard malloc(). You can use them without modifying your application simply by setting the LD_PRELOAD environment variable or adding the library to the /etc/preload.so configuration...