int main()
{
int *p;
p = malloc(5 * sizeof(int));
p =(int[5]) {11,12,13,14,15};
printf("[%d] [%d] [%d] [%d] [%d] \n",p[0],p[1],p[2],p[3],p[4]);
printf("[%lu] [%lu] [%lu] [%lu]\n",sizeof(&p[0]),sizeof(&p[1]),sizeof(&p[2]),sizeof(p));
printf("[%p] [%p] [%p] \n",&p[0],&p[1],p);
free(p);
return 0;
}
在运行 exe 时,我得到以下信息
[11] [12] [13] [14] [15]
[8] [8] [8] [8]
[0x7fff48ee93e0] [0x7fff48ee93e4] [0x7fff48ee93e0]
*** glibc detected *** ./a.out: double free or corruption (out): 0x00007fff48ee93e0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7eb96)[0x7fcce0856b96]
./a.out[0x40068a]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7fcce07f976d]
./a.out[0x4004c9]
======= Memory map: ========
00400000-00401000 r-xp 00000000 08:05 408246 /home/user1/Desktop/c/a.out
00600000-00601000 r--p 00000000 08:05 408246 /home/user1/Desktop/c/a.out
00601000-00602000 rw-p 00001000 08:05 408246 /home/user1/Desktop/c/a.out
00e54000-00e75000 rw-p 00000000 00:00 0 [heap]
7fcce05c2000-7fcce05d7000 r-xp 00000000 08:05 1314445 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fcce05d7000-7fcce07d6000 ---p 00015000 08:05 1314445 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fcce07d6000-7fcce07d7000 r--p 00014000 08:05 1314445 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fcce07d7000-7fcce07d8000 rw-p 00015000 08:05 1314445 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fcce07d8000-7fcce098d000 r-xp 00000000 08:05 1326756 /lib/x86_64-linux-gnu/libc-2.15.so
7fcce098d000-7fcce0b8c000 ---p 001b5000 08:05 1326756 /lib/x86_64-linux-gnu/libc-2.15.so
7fcce0b8c000-7fcce0b90000 r--p 001b4000 08:05 1326756 /lib/x86_64-linux-gnu/libc-2.15.so
7fcce0b90000-7fcce0b92000 rw-p 001b8000 08:05 1326756 /lib/x86_64-linux-gnu/libc-2.15.so
7fcce0b92000-7fcce0b97000 rw-p 00000000 00:00 0
7fcce0b97000-7fcce0bb9000 r-xp 00000000 08:05 1326744 /lib/x86_64-linux-gnu/ld-2.15.so
7fcce0d98000-7fcce0d9b000 rw-p 00000000 00:00 0
7fcce0db5000-7fcce0db9000 rw-p 00000000 00:00 0
7fcce0db9000-7fcce0dba000 r--p 00022000 08:05 1326744 /lib/x86_64-linux-gnu/ld-2.15.so
7fcce0dba000-7fcce0dbc000 rw-p 00023000 08:05 1326744 /lib/x86_64-linux-gnu/ld-2.15.so
7fff48eca000-7fff48eeb000 rw-p 00000000 00:00 0 [stack]
7fff48fdb000-7fff48fdd000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Aborted (core dumped)
释放内存时出了点问题,我无法弄清楚实际问题。请帮助在上述程序中释放内存的真正问题是什么