#include "BoostLog.h" #include "LeakTracer.h" #include "MemoryAllocationStackTracer.h" #include #include #include #include #include void test() { std::cout << boost::stacktrace::stacktrace(); malloc(20); } int make_memory_leak(void) { printf("%s:%d, 00!\n", __FILE__, __LINE__); int *ptr = (int *)malloc(sizeof(int)); // 分配内存块 *ptr = 0; // 构造内存泄露 printf("%s:%d, ptr= %p, *ptr= %d!\n", __FILE__, __LINE__, ptr, *ptr); char *p_new = new char[8 * 1024 * 1024]; (void)memset(p_new, 0, 8 * 1024 * 1024); *p_new = 0; printf("%s:%d, p_new= %p, *p_new= %d!\n", __FILE__, __LINE__, p_new, *p_new); return 0; } class Test { int a; }; int main(int argc, char const *argv[]) { LOG(info) << "hello world."; MemoryAllocationStackTracer::instance()->start(); auto a = new Test(); make_memory_leak(); MemoryAllocationStackTracer::instance()->dump(); return 0; }