Emptying two arrays with the same object causes "failed assertion `m_ref_count > 0'"
Here's some code: ------------------------------------- class MyThing { int x; } // Two identical arrays, typewise MyThing arga[0]; MyThing argb[0]; // Create an instance MyThing thing; 5 => thing.x; // Push it into arga arga << thing; // Push it into argb argb << thing; <<< "n=", arga[0].x >>>; <<< "n=", argb[0].x >>>; // clear arga 0 => arga.size; // clear argb - crash! 0 => argb.size; ------------------------------------- when I run it I get: ------------------------------------- $ chuck test. ck n= 5 n= 5 chuck_oo.cpp:120: failed assertion `m_ref_count > 0' Abort trap ------------------------------------- It seems that that 0 => arga.size decrements a reference count for thing, causing it to be freed, and then when the same thing is attempted for argb, it crashes. Possibly some reference increment missing when doing argb << thing ? /Stefan -- Release me, insect, or I will destroy the Cosmos!
2010/5/22 Stefan Blixt
Here's some code:
Hey, Stefan!
It seems that that 0 => arga.size decrements a reference count for thing, causing it to be freed, and then when the same thing is attempted for argb, it crashes. Possibly some reference increment missing when doing argb << thing ?
I agree, especially because we already knew that the ref-count has a bug or two. I think this is a new side to that. Nice catch. Kas.
participants (2)
-
Kassen
-
Stefan Blixt