0

-edit2- I was going down the wrong path. I solved it by correcting one typo and adding one line to fix an oversight that allowed me to write 4 bytes to many over an array.

-edit- maybe i am running through a wrong path. Maybe VS is showing me incorrect data but still runs the code properly (after all my code does show the correct name). But i have no idea where else my heap corruption could come from.

I havent notice any problems or incorrect data. But i have notice random crashes and suggestions that its caused by corrupting the heap.

I looked into something and this is what i notice. I have a class at address 0x00216e98. In my watch i can see the data correctly and below you can see the name ptr is 21bc00. I return the ptr as a base class (lets call it Base) which is inserted into a deque. As you can see in the deque (ls) it has one element and the first element is the correct pointer (i thought it may adjust but i guess not. But maybe it is but.....).

However the members it holds is COMPLETELY INCORRECT cdcdcd00 does not look like a valid name ptr to me and does not match to the ptr below. Also when my code is ran i somehow get the correct name and such so i dont know whats going on/wrong. It could be dynamic_cast magic but anyways if i am still grabbing the correct data i dont know how i am corrupting the heap (in both gcc and msvc).

I'll note i have diamond inheritance to the 'Base' class however like i said i am still pulling the correct data and i am not using virtual with base.

enter image description here

trincot
  • 317,000
  • 35
  • 244
  • 286
  • Are you inserting `Base *` or `Base` into deque? – Blazes Jun 01 '11 at 14:54
  • [this resource](http://www.codeguru.com/cpp/w-p/win32/tutorials/article.php/c9535) should be useful to you. Basically, you're running into uninitialized memory. – Alexandre C. Jun 01 '11 at 14:56
  • Actually neither. I am inserting `D2*` which inherits from `Base*` which is the right side of my diamond. However `D2` doesnt have a diamond problem and is always on the right side. Base holds serialization code and a few classes need both D1 and D2 (which are both empty). D1 and D2 just distinguish the type i am expecting. Some classes can go into both main list which causes my diamond problem. –  Jun 01 '11 at 15:00
  • @Alexandr: I am not USING uninitialized memory (well, my code). Each member is wrapped around a template which is why you see is_set and v in all the members. The code is pure evil and this has saved me a lot with generated code that checks each member for true before dumping. Also my output SHOWS all the data correctly... –  Jun 01 '11 at 15:02
  • @acidzombie24: the `v` members look as if they have not been initialized, and slightly bitwise modified afterward. – Alexandre C. Jun 01 '11 at 15:09
  • @Alex: Like i said. They are initialize and it shows it. However looking through the deque/ls shows it wrong. This actually one screenshot i cut up –  Jun 01 '11 at 15:52
  • @acid: It would be nice if you could provide some code. Otherwise we could just guess what's happening. – rtn Jun 01 '11 at 16:13
  • @Magnus: Theres 28k lines of code. Which do you think i should show? –  Jun 01 '11 at 17:07

2 Answers2

1

If you are using linux you might be able to use Valgrind. This is an exellent tool for finding heap related issues.

doron
  • 27,972
  • 12
  • 65
  • 103
  • Obviously OP is not. The screenshot looks like VS2010. – Alexandre C. Jun 01 '11 at 15:13
  • There are also some memory validating tools for Windows with a free trial version. (Putting this in a search engine should show some results) – jszpilewski Jun 01 '11 at 15:15
  • I tried valgrind out and used `valgrind --leak-check=no`. Theres too many messages. I cant see them all and i cant seem to redirect the msg to a file. Is there a way for me to silence errors about losing data? What flags do you suggest i have on? –  Jun 01 '11 at 15:51
  • wow valgrind is great and all this time i thought it only did memory leaks and profiling. In the 2740 lines of code only one line had to be changed (in a C file i used strdup instead of mystrdup oops) and one had to be added in a critical section which allowed up to 4byte overwrite. I dont know why VS didnt detect the 2nd. Anyways great suggestion. Also that 2740 is just code i wrote by hand. The rest is generated coming to the total of 28,264 lines. This isnt including the lines required to write those tools. –  Jun 01 '11 at 17:05
1

In debug mode cdcdcdcd is deleted uninitialized memory that the debug heap is marking for you.

If you see that, you are using a pointer to a deleted structure. memory that was allocated but never given a value.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
  • 0xCDCDCDCD is *uninitialized* memory: http://stackoverflow.com/questions/127386/in-visual-studio-c-what-are-the-memory-allocation-representations – Necrolis Jun 01 '11 at 15:34
  • @Necrolis - Right, I got it mixed up with DD DD DD DD :-) – Bo Persson Jun 01 '11 at 15:40
  • Right. But like i said. This is what visual studio is SHOWING me. My code actually runs correctly and has checks (see my question comment) for iniatlizing memory. None of my pointers are CDCDCDCD as my screenshot shows. But like i said it also shows it wrong as well but my code is running correctly -edit- its the heap error i am looking for –  Jun 01 '11 at 15:49