|
From: Christian K. <chr...@tu...> - 2006-05-15 08:23:21
|
Andy, > The code in question is for a reference counted chunk of memory. Its > created in one thread and freed in another. Its protected by a mutex, > which is why I pretty sure I'm not freeing it twice. While I have the > mutex, I free and then NULL out the pointer. Even it did get called > twice, the pointer would be NULL, so I would not get a double-free. I'm not sure if this could be related to your findings, but the last sentence rings me a bell. I had a similar issue once and it turned out that with compiler optimization enabled the check for a null pointer in delete seemed to vanish. I had to explicitly check for null before calling delete in order to avoid the double free. Unfortunately I don't recall the exact circumstances right now, but it might be worth a try. Cheers, Christian -- Christian Keil /"\ Institute for Reliable Computing \ / ASCII Ribbon Campaign Hamburg University of Technology X against HTML email & vCards mail:c....@tu... / \ |
|
From: Dennis L. <pla...@in...> - 2006-05-15 16:33:46
|
Am Montag, den 15.05.2006, 10:22 +0200 schrieb Christian Keil: > Andy, > > > The code in question is for a reference counted chunk of memory. Its > > created in one thread and freed in another. Its protected by a mutex, > > which is why I pretty sure I'm not freeing it twice. While I have the > > mutex, I free and then NULL out the pointer. Even it did get called > > twice, the pointer would be NULL, so I would not get a double-free. > > I'm not sure if this could be related to your findings, but the last > sentence rings me a bell. I had a similar issue once and it turned out > that with compiler optimization enabled the check for a null pointer in > delete seemed to vanish. I had to explicitly check for null before > calling delete in order to avoid the double free. Unfortunately I don't > recall the exact circumstances right now, but it might be worth a try. Code like: if( ptr != NULL) delete ptr; ptr = NULL; is unnecessary. The following is well defined: delete ptr; ptr = 0; as delete on a nullpointer will have no effect. greets Dennis PS: You should maybe check the backtrace it gives, where the ptr was deleted the first time. And maybe add some debugoutput *after* setting the ptr to 0. Although its evil to throw from within a dtor, this could be one of the reasons the 0 assign never was reached. |