Simple malloc trace to detect memory leak in a c/c++ program
Use dlsym() to hook libc malloc functions in attribute((constructor)) function which would be called before main(). Implementation malloc/free ... functions with the hooked functions and record memory alloc/free history, specially store backtrace for all alloced memory. Detect memory leak in attribute((distructor)) function which would be called after main().