-1

Im working on a data structures assignmnet and something very strange is happening , my structure contains of 4 avl trees , in the destructor of the structre I delete the 4 trees using delete (the trees are allocated with new in the constructor) , a method of the class is called Quit and all it does is "delete this" calling the destructor , when calling Quit and before it operates any command (before doing the "delete this" ) two of the avl trees are already null and one is with adress 0x1 and one is with legal adress but the right and left sons of the root are 0xabababababababab and 0xfeeefeeefeeefeee so when calling the destructor and trying to delete them a SEGMENTAION FAULT or SEGTRAP accures , because 0xabababababababab is not NULL and there for the fucnction does not enter the if(!node){return;} and calls the recursively for the right son , and that where the seg fault happens , because accessing fields of 0xababababababab is like accessing fields of NULL a pic of the structures trees before entering "Quit"

what I dont understand is when does this happen to the trees ? because when debugging , in the end of the last function before Quit the fields and trees are all 100% as expected to be so nothing of them is deleted of changed in any way in the code. I spent days trying to find the problem , PLEASE HELP. THANK YOU IN ADVANCE.

saleem ar
  • 1
  • 2
  • If the answer is not yet sufficiently clear to you that it allows you to fix your program, one way you can proceed is to post a minimally reproducible example. That will allow people to tell you why the segmentation fault occurred. – Tim Boddy May 30 '21 at 14:20

1 Answers1

2

0xABABABAB is used by HeapAlloc() to mark "no man's land" guard bytes after allocated memory on the heap. If you access this, you probably have a buffer overflow.

0xFEEEFEEE is used by HeapFree() to mark freed heap memory. If you access this, you probably have a double free.

Note that the memory layout is different in Debug Build and Release Build. You may not get that error in debug builds.

Also note that the memory layout is different when running the app within an IDE (debugger attached from start) and when running without a debugger. You may not get that error when running from inside the IDE.

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222