简体   繁体   中英

How to debug and fix this double free memory corruption issue for specific case

I have a QT based GUI when I exit the tool, I get this following issue

*** glibc detected *** /bin/linux_x86_64/main-g: double free or corruption 
(!prev): 0x00000000049eca50 ***
  ======= Backtrace: =========
   /lib64/libc.so.6[0x3feee75e66]
   /lib64/libc.so.6[0x3feee789b3]
    /linux_x86_64/main2- 
   g(_ZN9__gnu_cxx13new_allocatorIPN3zi_14PCommandEE10deallocateEPS3_m+0x20) 
  [0x1d9f504]
 gui//../bin/linux_x86_64/main2-g 

  _ZNSt16allocator_traitsISaIPN3zi_14PCommandEEE10deallocateERS3_PS2_m+0x2b) 
  [0x1d9f0de]
 /gui//../bin/linux_x86_64/main2-g   
(_ZNSt12_Vector_baseIPN3zi_14PCommandESaIS2_EE13_M_deallocateEPS2_m+0x32) 
[0x1d9eba6]
/gui//../bin/linux_x86_64/main2- 
 g(_ZNSt12_Vector_baseIPN3zi_14PCommandESaIS2_EED2Ev+0x41)[0x1d9e955]
../bin/linux_x86_64/main2-g(_ZNSt6vectorIPN3zi_14PCommandESaIS2_EED1Ev+0x41) 
 [0x1dc771b]
/lib64/libc.so.6(__cxa_finalize+0x9d)[0x3feee35ebd]
 ../lib/linux_x86_64/lib-g.so(+0x3a627c6)[0x7f63
 ====== Memory map: ========
 00400000-02b5f000 r-xp 00000000 08:03 21767481                           
   ../main2-g
 02d5e000-02f8c000 rw-p 0275e000 08:03 21767481                           
../main2-g
  02f8c000-03222000 rw-p 00000000 00:00 0 
03cc7000-04cac000 rw-p 00000000 00:00 0    

I need some inputs to debug this issue. I am also not able to use Valgrind . It crashes before this case

One of your delete or free calls are done on already freed memory. Go through all your manual memory deallocations and check if they are correct (remove suspicious ones and see if it changes the behaviour).

Ideally using modern C++ you should have small or no need for explicit new and delete (use std provided smart pointers).

Regarding Qt, beware that Qt uses a parent child ownership. You should only delete "top" objects (ones that has no "parent" set), Qt will delete all children of a deleted object on its own. ie if you have manually allocated a QObject derived instance and in some way chained it into an QObject hierarchy (add child/set parent/ etc), deleting that object directly will cause trouble.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM