C++ 在回溯跟踪中取消分配'delete'时获取'free()'错误
我从gdb得到以下错误:C++ 在回溯跟踪中取消分配'delete'时获取'free()'错误,c++,debugging,ipopt,C++,Debugging,Ipopt,我从gdb得到以下错误: *** glibc detected *** /.root0/autohome/u132/hsreekum/ipopt/ipopt/debug/Ipopt/examples/ex3/ex3: free(): invalid next size (fast): 0x0000000120052b60 *** 这是回溯: #0 0x000000555626b264 in raise () from /lib/libc.so.6 #1 0x000000555626cc6c
*** glibc detected *** /.root0/autohome/u132/hsreekum/ipopt/ipopt/debug/Ipopt/examples/ex3/ex3: free(): invalid next size (fast): 0x0000000120052b60 ***
这是回溯:
#0 0x000000555626b264 in raise () from /lib/libc.so.6
#1 0x000000555626cc6c in abort () from /lib/libc.so.6
#2 0x00000055562a7b9c in __libc_message () from /lib/libc.so.6
#3 0x00000055562aeabc in malloc_printerr () from /lib/libc.so.6
#4 0x00000055562b036c in free () from /lib/libc.so.6
#5 0x000000555561ddd0 in Ipopt::TNLPAdapter::~TNLPAdapter ()
from /home/ba01/u132/hsreekum/ipopt/ipopt/build/lib/libipopt.so.1
#6 0x00000055556a9910 in Ipopt::GradientScaling::~GradientScaling ()
from /home/ba01/u132/hsreekum/ipopt/ipopt/build/lib/libipopt.so.1
#7 0x00000055557241b8 in Ipopt::OrigIpoptNLP::~OrigIpoptNLP ()
from /home/ba01/u132/hsreekum/ipopt/ipopt/build/lib/libipopt.so.1
#8 0x00000055556ae7f0 in Ipopt::IpoptAlgorithm::~IpoptAlgorithm ()
from /home/ba01/u132/hsreekum/ipopt/ipopt/build/lib/libipopt.so.1
#9 0x0000005555602278 in Ipopt::IpoptApplication::~IpoptApplication ()
from /home/ba01/u132/hsreekum/ipopt/ipopt/build/lib/libipopt.so.1
#10 0x0000005555614428 in FreeIpoptProblem ()
from /home/ba01/u132/hsreekum/ipopt/ipopt/build/lib/libipopt.so.1
#11 0x0000000120001610 in main () at ex3.c:169`
下面是Ipopt::TNLPAdapter::~TNLPAdapter()
我的问题是:为什么
free()
在~TNLPAdapter()
使用delete[]
时抛出错误?此外,我还想单步执行~TNLPAdapter()
,以便查看是哪个释放导致了错误。我相信错误发生在外部库(IPOPT)中,但我编译它时启用了调试标志;这是否足够?新[]/删除[]
后的原始内存分配/释放机制通常与malloc使用的机制相同。原始内存分配/释放函数的标准库实现operator new[]
/operator delete[]
实际上可以直接调用malloc
和free
。因此,即使您使用的是delete[]
,由free
报告错误也毫不奇怪
您得到的错误表明堆的完整性受到了破坏。堆破了。问题的根源可能在该函数中(双重空闲?)或在完全不同的位置(双重空闲或内存溢出?)。从你发布的代码中无法得知发生了什么
找出哪个对
delete[]
的特定调用报告了问题,并查看是否有其他代码覆盖了该内存块。或者只是使用一些外部工具,比如valgrind来抓捕罪犯。新[]/删除[]
背后的原始内存分配/释放机制通常与malloc
/免费[/code>使用的机制相同。原始内存分配/释放函数的标准库实现operator new[]
/operator delete[]
实际上可以直接调用malloc
和free
。因此,即使您使用的是delete[]
,由free
报告错误也毫不奇怪
您得到的错误表明堆的完整性受到了破坏。堆破了。问题的根源可能在该函数中(双重空闲?)或在完全不同的位置(双重空闲或内存溢出?)。从你发布的代码中无法得知发生了什么
找出哪个对delete[]
的特定调用报告了问题,并查看是否有其他代码覆盖了该内存块。或者只是使用一些外部工具,如valgrind来抓捕罪犯。您是否对TNLPAdapter
实施或禁止复制?您是否对TNLPAdapter
实施或禁止复制?
TNLPAdapter::~TNLPAdapter()
{
delete [] full_x_;
delete [] full_lambda_;
delete [] full_g_;
delete [] jac_g_;
delete [] c_rhs_;
delete [] jac_idx_map_;
delete [] h_idx_map_;
delete [] x_fixed_map_;
delete [] findiff_jac_ia_;
delete [] findiff_jac_ja_;
delete [] findiff_jac_postriplet_;
delete [] findiff_x_l_;
delete [] findiff_x_u_;
}