malloc错误C ++ [英] malloc error C++
问题描述
可能重复:
malloc.c:3074错误?
Possible Duplicate:
malloc.c:3074 error?
我在执行C ++代码时遇到了这个奇怪的错误:
I am getting this strange error on execution of my C++ code:
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
程序可以正常运行,直到从已经执行的行捕获到上述Segmentation Fault(SIGSEGV).我使用gdb发现了这一点.
The program runs fine upto a point where it catches the above Segmentation fault(SIGSEGV) from an already executed line. I found out this using gdb.
推荐答案
某些地方由于写入无效的内存位置而损坏了堆.最可能的原因是在已分配对象的边界之外进行写入,或者在删除对象后对其进行写入.
Something has corrupted the heap by writing to an invalid memory location. The most likely causes are writing outside the bounds of an allocated object, or writing to an object after it has been deleted.
使用调试器很难追查这些错误.最好的工具是内存检查器,例如 valgrind .
These errors can be difficult to track down with a debugger. The best tool is a memory checker, such as valgrind.
这篇关于malloc错误C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!