*** glibc detected *** ./main: corrupted double-linked list: 0x086c4f30 ***
在此之后,程序不会退出,我被迫使用cntrl+C退出。我没有在我的整个代码中使用任何像"删除"这样的内存取消分配
在使用Valgrind时,我得到了以下信息:
Invalid write of size 4
==20358== at 0x8049932: main (main.cpp:123)
==20358== Address 0x432e6f8 is 0 bytes after a block of size 16 alloc'd
==20358== at 0x402C454: operator new[](unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==20358== by 0x8049907: main (main.cpp:120)
第123行中对应的代码是
float **der_global= new float *[NODES];
for(int i=0; i<no_element; i++)
{
der_global[i]=new float [no_element];
}
您原来的新调用为您提供了存储NODES指针的空间;但是for循环尝试设置它们的no_element,它不必是相同的数字。你的for循环应该有i小于NODES,而不是i小于no_element。
当程序释放不再有效的内存时,通常会出现此错误。你是在使用malloc还是任何其他动态分配。
如果你能添加一些你的代码,这将很容易解决你的问题
尝试使用valgrind
valgrind --tool=memcheck --leak-check=full --track-origins=yes --show-reachable=yes --log-file=val.log ./<executable> <parameters>
并查看val.log
您也可以使用gdb,但为此,您需要使用-g标签进行编译