2012-08-29 30 views
1

我從GDB以下錯誤:得到一個'免費()`錯誤的回溯與`delete`重新分配時

*** 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()

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_; 
    } 

我的問題是:爲什麼free()時拋出一個錯誤~TNLPAdapter()使用delete[]?另外,我想穿過~TNLPAdapter(),這樣我就可以看到哪個釋放會導致錯誤。我相信這個錯誤發生在外部庫(IPOPT)中,但我已經用調試標誌編譯它;這足夠嗎?後面new[]/delete[]

+0

您是否對「TNLPAdapter」執行或禁止複製? – hmjd

回答

5

原始內存分配/釋放機構通常是相同的,通過malloc/free使用的一個。原始內存分配/釋放函數operator new[]/operator delete[]的標準庫實現實際上可以直接調用mallocfree。出於這個原因,即使您使用的是delete [],也可以通過free報告錯誤,這並不令人驚訝。

您收到的錯誤表示堆的完整性被違反。堆被打破了。問題的根源可以在這個函數中(double free?),或者在一些完全不同的地方(double free或memory overrun?)。沒有辦法說明您發佈的代碼發生了什麼。

找出哪個特定的調用delete []報告問題,並查看是否有其他代碼覆蓋該內存塊。或者只是使用一些外部工具,如valgrind來抓到罪犯。