[vsipl++] [patch] Fix for Fir destructor not getting called

Stefan Seefeld stefan at codesourcery.com
Sun Jun 8 13:41:27 UTC 2008


Don McCoy wrote:
> This patch fixes a problem in which the Ref_counted_ptr holder's count_
> member was being incremented one too many times, resulting in the Fir
> destructor not getting called.
> 
> The problem occurs because in the dispatch mechanism
> (Evaluator::exec()), the Fir_impl backend is created and stored in a
> Ref_counted_ptr object, then passed to the Fir class and stored in yet
> another Ref_counted_ptr object.  This results in a reference count of 2
> after creation, inhibiting the destructor from being called when the Fir
> object goes out of scope.
> 
> While this does in fact fix the problem, I would like to verify that it
> is the correct fix in this case.  Comments?

Yes, I believe this is the correct fix: the created objects are of type 
Ref_count, which initializes the counter to 1. When we pass the newly 
created object to Ref_counted_ptr, we really mean to hand the object's 
ownership to it, too, so we must *not* increment the counter.

I have to admit that I find the ref counting API still quite confusing...

Regards,
		Stefan


-- 
Stefan Seefeld
CodeSourcery
stefan at codesourcery.com
(650) 331-3385 x718



More information about the vsipl++ mailing list