本帖最后由 zqh1630 于 2013-4-18 13:36 编辑
是不是在while(1)中不能用malloc和free, 我就是在
while(1){
buf = NULL;
if(condition)
buf = malloc();
if(buf != NULL)
free(buf);
}
写的程序,是这个具体流程,
但是运行一段时间后,会出现如下错误代码:
不知道为啥?
*** glibc detected *** ./a.out: double free or corruption (top): 0x09891118 ***
======= Backtrace: =========
/lib/i686/nosegneg/libc.so.6[0x670716]
/lib/i686/nosegneg/libc.so.6(cfree+0x90)[0x673c80]
./a.out[0x8048d99]
/lib/i686/nosegneg/libc.so.6(__libc_start_main+0xdc)[0x61cdec]
./a.out[0x8048611]
======= Memory map: ========
005e9000-00603000 r-xp 00000000 fd:00 4228679 /lib/ld-2.5.so
00603000-00604000 r--p 00019000 fd:00 4228679 /lib/ld-2.5.so
00604000-00605000 rw-p 0001a000 fd:00 4228679 /lib/ld-2.5.so
00607000-00747000 r-xp 00000000 fd:00 4228694 /lib/i686/nosegneg/libc-2.5.so
00747000-00749000 r--p 00140000 fd:00 4228694 /lib/i686/nosegneg/libc-2.5.so
00749000-0074a000 rw-p 00142000 fd:00 4228694 /lib/i686/nosegneg/libc-2.5.so
0074a000-0074d000 rw-p 0074a000 00:00 0
0077e000-00791000 r-xp 00000000 fd:00 4228696 /lib/i686/nosegneg/libpthread-2.5.so
00791000-00792000 r--p 00012000 fd:00 4228696 /lib/i686/nosegneg/libpthread-2.5.so
00792000-00793000 rw-p 00013000 fd:00 4228696 /lib/i686/nosegneg/libpthread-2.5.so
00793000-00795000 rw-p 00793000 00:00 0
008d0000-008db000 r-xp 00000000 fd:00 4227283 /lib/libgcc_s-4.1.2-20080102.so.1
008db000-008dc000 rw-p 0000a000 fd:00 4227283 /lib/libgcc_s-4.1.2-20080102.so.1
00ea6000-00ea7000 r-xp 00ea6000 00:00 0 [vdso]
08048000-0804a000 r-xp 00000000 fd:00 3255675 /nfs/ipcamera/a.out
0804a000-0804b000 rw-p 00001000 fd:00 3255675 /nfs/ipcamera/a.out
09891000-098b2000 rw-p 09891000 00:00 0
b7400000-b7421000 rw-p b7400000 00:00 0
b7421000-b7500000 ---p b7421000 00:00 0
b75a3000-b75a4000 ---p b75a3000 00:00 0
b75a4000-b7fa5000 rw-p b75a4000 00:00 0
b7fb9000-b7fbb000 rw-p b7fb9000 00:00 0
bfafd000-bfb13000 rw-p bfafd000 00:00 0 [stack]
已放弃 |