神秘的malloc:SYSMALLOC:断言失败错误 [英] Mysterious malloc: sysmalloc: Assertion failed error
问题描述
我得到一个神秘的错误,我不知道为什么。这code失败之前运行几次,它总是在同一点失败。
I am getting a mysterious error and I have no idea why. This code runs several times before failing, and it always fails at the same point.
下面是我的code:
assert(size > 0);
int* sorted = malloc(size * sizeof(int));
这是我得到的错误,当我运行它:
And here is the error I am getting when I run it:
malloc.c:2369: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.
我试图打印出的大小和它在这种情况下为1。这code。与之前没有不同大小的值,包括1,运行了好几次。
I have tried printing out size and it is 1 in this case. This code runs several times with varying values of size, including 1, before failing.
有没有人有任何想法,我做错了?
Does anyone have any idea what I am doing wrong?
感谢。
推荐答案
当您的code 免费
在一些以前的时间D无效地址这通常发生,或写过去分配的内存块的末尾。通过Valgrind的或其他一些内存分析器运行code,看看那里发生这种情况的地步。
This usually happens when your code free
d an invalid address at some prior time, or wrote past the end of the allocated memory block. Run your code through valgrind or some other memory profiler to see the point where this happens.
这篇关于神秘的malloc:SYSMALLOC:断言失败错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!