Browse - Programming Tips - Control what happens with malloc() / free() prorammming errors

Date: 2018dec7
OS: Linux
Language: C/C++

Q.  Control what happens with malloc() / free() prorammming errors

A.  The mallopt(M_CHECK_ACTION, ...) can control when happens
with you double free or other allocation mistakes.
Do:

mallopt(M_CHECK_ACTION, option);
Where option is:
0 Ignore error conditions; continue execution (with undefined results). 1 Print a detailed error message and continue execution. 2 Abort the program. 3 Print detailed error message, stack trace, and memory mappings, and abort the program. The default. 5 Print a simple error message and continue execution. 7 Print simple error message, stack trace, and memory mappings, and abort the program.
Notice by miss-using this you could generate a stack trace any time you want.