malloc 调测之分配、释放

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    void *chunk1;
    void *chunk2;
    void *chunk3;
    void *chunk4;

    chunk1 = malloc(24);
    strcpy(chunk1, "abcde");
     free(chunk1);
    
    chunk2 = malloc(24);
    strcpy(chunk2, "12345");
    free(chunk2);
    
    chunk3 = malloc(24);
    strcpy(chunk3, "98765");
    free(chunk3);
    
    chunk4 = malloc(24);
    strcpy(chunk4, "23456");
    free(chunk4);
    
    return 0;
}

#if 0
12        chunk1 = malloc(24);
(gdb) x/48wx chunk1
0x42ca3000:    0x42ca2d88    0x42aff316    0x00000000    0x42c1dc70
0x42ca3010 <realloc@got.plt>:    0x42b60de0    0x42b60920    0x42b90510    0x42b61110
0x42ca3020 <*ABS*@got.plt>:    0x42b7e740    0x42c3cd00    0x42ad7e40    0x42b61250
0x42ca3030 <___tls_get_addr@got.plt>:    0x42ad6fa0    0x42b60ce0    0x42c42c90    0x00000000
0x42ca3040 <__libc_multiple_libcs>:    0x00000001    0x0000037f    0x00000040    0x00000022
0x42ca3050:    0x00000000    0x00000000    0x00000000    0x00000000
0x42ca3060 <randtbl>:    0x00000003    0x991539b1    0x16a5bce3    0x6774a4cd
0x42ca3070 <randtbl+16>:    0x3e01511e    0x4e508aaa    0x61048c05    0xf5500617
0x42ca3080 <randtbl+32>:    0x846b7115    0x6a19892c    0x896a97af    0xdb48f936
0x42ca3090 <randtbl+48>:    0x14898454    0x37ffd106    0xb58bff9c    0x59e17104
0x42ca30a0 <randtbl+64>:    0xcf918a49    0x09378c83    0x52c7a471    0x8d293ea9
0x42ca30b0 <randtbl+80>:    0x1f4fc301    0xc3db71be    0x39b44e1c    0xf8a44ef9
(gdb) n
13        strcpy(chunk1, "abcde");
(gdb) 
14         free(chunk1);
(gdb) x/48wx chunk1-8
0x804b000:    0x00000000    0x00000021    0x64636261    0x00000065
0x804b010:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b020:    0x00000000    0x00020fe1    0x00000000    0x00000000
0x804b030:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b040:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b050:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b060:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b070:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b080:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b090:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b0a0:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b0b0:    0x00000000    0x00000000    0x00000000    0x00000000
(gdb) n
16        chunk2 = malloc(24);
(gdb) x/48wx chunk1-8
0x804b000:    0x00000000    0x00000021    0x00000000    0x00000065
0x804b010:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b020:    0x00000000    0x00020fe1    0x00000000    0x00000000
0x804b030:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b040:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b050:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b060:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b070:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b080:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b090:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b0a0:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b0b0:    0x00000000    0x00000000    0x00000000    0x00000000
(gdb) n
17        strcpy(chunk2, "12345");
(gdb) 
18        free(chunk2);
(gdb) x/48wx chunk1-8
0x804b000:    0x00000000    0x00000021    0x34333231    0x00000035
0x804b010:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b020:    0x00000000    0x00020fe1    0x00000000    0x00000000
0x804b030:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b040:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b050:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b060:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b070:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b080:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b090:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b0a0:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b0b0:    0x00000000    0x00000000    0x00000000    0x00000000
(gdb) n
20        chunk3 = malloc(24);
(gdb) x/48wx chunk1-8
0x804b000:    0x00000000    0x00000021    0x00000000    0x00000035
0x804b010:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b020:    0x00000000    0x00020fe1    0x00000000    0x00000000
0x804b030:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b040:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b050:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b060:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b070:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b080:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b090:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b0a0:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b0b0:    0x00000000    0x00000000    0x00000000    0x00000000
(gdb) n
21        strcpy(chunk3, "98765");
(gdb) 
22        free(chunk3);
(gdb) x/48wx chunk1-8
0x804b000:    0x00000000    0x00000021    0x36373839    0x00000035
0x804b010:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b020:    0x00000000    0x00020fe1    0x00000000    0x00000000
0x804b030:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b040:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b050:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b060:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b070:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b080:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b090:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b0a0:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b0b0:    0x00000000    0x00000000    0x00000000    0x00000000
(gdb) n
24        chunk4 = malloc(24);
(gdb) x/48wx chunk1-8
0x804b000:    0x00000000    0x00000021    0x00000000    0x00000035
0x804b010:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b020:    0x00000000    0x00020fe1    0x00000000    0x00000000
0x804b030:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b040:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b050:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b060:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b070:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b080:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b090:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b0a0:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b0b0:    0x00000000    0x00000000    0x00000000    0x00000000
(gdb) n
25        strcpy(chunk4, "23456");
(gdb) 
26        free(chunk4);
(gdb) x/48wx chunk1-8
0x804b000:    0x00000000    0x00000021    0x35343332    0x00000036
0x804b010:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b020:    0x00000000    0x00020fe1    0x00000000    0x00000000
0x804b030:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b040:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b050:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b060:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b070:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b080:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b090:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b0a0:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b0b0:    0x00000000    0x00000000    0x00000000    0x00000000
(gdb) n
28        return 0;
(gdb) x/48wx chunk1-8
0x804b000:    0x00000000    0x00000021    0x00000000    0x00000036
0x804b010:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b020:    0x00000000    0x00020fe1    0x00000000    0x00000000
0x804b030:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b040:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b050:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b060:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b070:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b080:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b090:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b0a0:    0x00000000    0x00000000    0x00000000    0x00000000
0x804b0b0:    0x00000000    0x00000000    0x00000000    0x00000000
(gdb) n
29    }

#endif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值