1 Star 0 Fork 0

tangzh/malloc_debug

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
mtrace.c 1.86 KB
一键复制 编辑 原始数据 按行查看 历史
zonghui.tang 提交于 2021-05-28 18:13 . add mtrace test
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
//export MALLOC_TRACE=a.log
//./mtrace
//tangzh@fanvil:~/work-1-11/code/project/malloc_debug$ mtrace mtrace a.log
//
//Memory not freed:
//-----------------
// Address Size Caller
// 0x000000000163e4a0 0x3 at /home/tangzh/work-1-11/code/project/malloc_debug/mtrace.c:51
void getMemStatus()
{
struct mallinfo info = mallinfo();
printf("arena = %d\n", info.arena);
printf("ordblks = %d\n", info.ordblks);
printf("smblks = %d\n", info.smblks);
printf("hblks = %d\n", info.hblks);
printf("hblkhd = %d\n", info.hblkhd);
printf("usmblks = %d\n", info.usmblks);
printf("fsmblks = %d\n", info.fsmblks);
printf("uordblks = %d\n", info.uordblks);
printf("fordblks = %d\n", info.fordblks);
printf("keepcost = %d\n", info.keepcost);
}
int main()
{
#if 0
char atCommand[90]="+IREG:02E9EFAF2E,6,01\r\n";//"+TIME:05:56:21,+ 02:00 GMT\r\n";
char *ptr[4];
ptr[0] = strtok((char*)atCommand, ":,\n");
ptr[1] = strtok(NULL, ":,\n");
ptr[2] = strtok(NULL, ":,\n");
ptr[3] = strtok(NULL, ":,\n");
printf("Hello world,\n ptr[0]=%s ,ptr[1]=%s ,ptr[2]=%s, ptr[3]=%s\n",ptr[0],ptr[1],ptr[2],ptr[3]);
int h,m,s;
int diff_gmt_h,diff_gmt_m;
char diff;
sscanf("+TIME:05:56:21,+ 02:00 GMT","+TIME:%d:%d:%d,%c %d:%d GMT", &h,&m,&s,&diff,&diff_gmt_h,&diff_gmt_m);
printf("h=%d,m=%d,s=%d,diff=%c,diff_gmt_h=%d,diff_gmt_m=%d\n",h,m,s,diff,diff_gmt_h,diff_gmt_m);
scanf("%d %d",&h,&diff);
printf("s eeeeeeeeeeeeeeeeeeeeee %d, %u h=%d diff=%d \n",strlen("a"),pthread_self(),h,diff);
switch('a'){
case 'a':
printf("ssssssssss\n");
break;
}
#endif
mtrace();
char ** p=malloc(8);
p[0]=malloc(2);
p[1]=malloc(3);
free(p[0]);
//free(p[1]);
if(p[1])free(p);
getMemStatus();
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/tangzh666/malloc_debug.git
git@gitee.com:tangzh666/malloc_debug.git
tangzh666
malloc_debug
malloc_debug
master

搜索帮助