内存泄漏mtrac使用
文章目录
1 内存泄漏
bad_alloc
terminate called after throwing an instance of ‘std::bad_alloc’
what():std::bad_alloc
上下文分析:在函数update_change_node()打印完 updata_change_node start之后就没报异常了
mtrace:
相关技术博客:
https://www.cnblogs.com/yangykaifa/p/7397497.html
https://www.jianshu.com/p/d9e12b66096a
配置环境变量:
1)export MALLOC_TRACE=/home/centos/gnuc/c3/trace.log
2)setenv(“MALLOC_TRACE”, “taoge.log”, “1”);
#include <stdlib.h>
#include <stdio.h>
#include <mcheck.h>
int main(int argc, char **argv)
{
setenv("MALLOC_TRACE", "taoge.log", "1");
mtrace();
char * p = malloc(100);
free(p);
p = malloc(1000);
muntrace();
return 0;
}