内存在分配的块末尾消失

时间:2018-09-06 16:35:44

标签: heap-corruption

以下是GDB会话中的相关代码段:

item_destroy (item=0x641f40) at hash.c:228
228   if( item == NULL ) // Make sure I'm dealing with a non-null item
(gdb) n
230   mstatus = mprobe( item->key );
(gdb) n
231   if( mstatus == MCHECK_OK ) // Check to make sure everything is good
(gdb) p mstatus  (Double check at execution time)
$1 = MCHECK_OK  <- Yep we're good
(gdb) n
232     free( item->key );  // If was true
(gdb) n
memory clobbered past end of allocated block

Program received signal SIGABRT, Aborted.
0x00007ffff693c277 in raise () from /lib64/libc.so.6

我想不出这怎么可能。需要明确的是,这不是一段多线程的代码,并且在执行该特定例程之前,已经多次调用了该例程。如果有的话,似乎与数据有关。 item-> key此时为“ 0”,实际上是null终止。它被分配为malloc(3),因为我将密钥长度加2。 1代表终止的null我插入,另外一个仅仅因为。可能是对齐的东西吗?

0 个答案:

没有答案