为什么我得到一个C的malloc断言失败?
我推行分而治之多项式算法,所以我可以基准它针对OpenCL实现,但我不能让的malloc
工作。当我运行该程序,它分配了一堆东西,检查一些东西,然后发送尺寸/ 2
来的算法。然后,当我再次打了的malloc
行就吐出了这一点:
I am implementing a divide and conquer polynomial algorithm so I can benchmark it against an OpenCL implementation, but I can't get malloc
to work. When I run the program, it allocates a bunch of stuff, checks some things, then sends the size/2
to the algorithm. Then when I hit the malloc
line again it spits out this:
malloc.c:3096:SYSMALLOC:断言`(old_top ==(((mbinptr)(((字符*)及((AV) - >仓[((1) - 1)* 2)) - __builtin_offsetof(结构个malloc_chunk,FD))))及和放大器; old_size == 0)|| ((无符号长)(old_size)> =(无符号长)((((__ builtin_offsetof(结构个malloc_chunk,fd_nextsize))+((2 *(sizeof的(为size_t))) - 1))及〜((2 *(的sizeof(为size_t))) - 1)))及及((old_top) - >尺寸和放大器;为0x1)及及((无符号长)OLD_END&安培; pagemask)== 0)'失败。
中止
malloc.c:3096: 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. Aborted
有问题的行是:
int *mult(int size, int *a, int *b) {
int *out,i, j, *tmp1, *tmp2, *tmp3, *tmpa1, *tmpa2, *tmpb1, *tmpb2,d, *res1, *res2;
fprintf(stdout, "size: %d\n", size);
out = (int *)malloc(sizeof(int) * size * 2);
}
我查了尺寸fprintf中
,它是一个正整数(通常为50在这一点)。我试着打电话的malloc
与普通的数字,以及和我仍然得到错误。我只是在难倒这是怎么回事,和谷歌没有什么到目前为止,我发现是有帮助的。
I checked size with a fprintf
, and it is a positive integer (usually 50 at that point). I tried calling malloc
with a plain number as well and I still get the error. I'm just stumped at what's going on, and nothing from Google I have found so far is helpful.
任何想法是怎么回事?我试图找出如何编译一个新的海湾合作委员会的情况下,这是一个编译器错误,但我真的很怀疑。
Any ideas what's going on? I'm trying to figure out how to compile a newer GCC in case it's a compiler error, but I really doubt it.
99.9%的可能是你已经损坏的内存(过度或流动的缓冲区,写信给之后被释放,同所谓的自由两次指针指针等)
99.9% likely that you have corrupted memory (over- or under-flowed a buffer, wrote to a pointer after it was freed, called free twice on the same pointer, etc.)
运行您的code下 Valgrind的的,看看你的程序做了一些不正确。
Run your code under Valgrind to see where your program did something incorrect.