I have a pointer to a given class. Lets say, for example, the pointer is:
0x24083094
That pointer points to:
0x03ac9184
Which is the virtual function table of my class. That makes sense to me. In windbg, everything looks correct.
I delete said pointer. Now at 0x24083094 is:
0x604751f8
But it isn't some random garbage, that address is put in there every time, it is consistently 0x604751f8! So much so that I can actually use that address to determine if that pointer was deleted, between executions of my application!
But Why? How does it determine that 0x604751f8 should be written there?
For the record, I am using windows, building under visual studio 2003.
EDIT: I know I can't rely on that value being set, even if it does appear to be consistent, but can I rely on it being different? ie, 0x03ac9184 will not be at 0x24083094 if the pointer is deleted, right? WHAT is put there could be anything, but 0x03ac9184 will definitely not be there (or else I could still call methods, since that is the virtual function table). Am I right?
Second EDIT: I feel like I have answer... can't rely on anything after it is deleted. Maybe some background will help people see where I am coming from. Essentially, I am trying to fix a bug where a pointer gets deleted out from under me. Its a long story, I won't go into the details. Basically, I am trying to detect that I am in this situation, so I can exit gracefully from my function. I suppose the easiest and best way is to just figure out who actually owns this pointer, and ask him if anything has changed. So I am going to implement a fix like that. It avoids any of this c++ delete hacker-y I was discussing.
HOWEVER, the interesting thing is that in our code we have a class called 'BogusObject' that essentially acts as a tray catching people that accidentally dereference freed objects. Basically, we hook our own delete functions and bash the BogusObject class into the vtable of any freed class. Then if someone calls something they get a nice message saying something to the effect of "hey, something is wrong dude.". This is happening in my case. ie 0x604751f8+(someoffset) is inside the BogusObject class. BUT WE NO LONGER USE BOGUSOBJECT!!!! It literally isn't setup anywhere (even links properly if I completely remove the BogusObject class), and yet I still end up getting the nice message saying something is wrong! But I am now of the opinion that it is a coincidence.
For some reason the runtime is putting that 0x604751f8 value in this pointer when it is deleted, and that just happens to correspond with the one class that has a purpose to catch situations like this! weird. But on to bigger and better bugs!
thanks for the help!