scope(exit) & stack => double free or corruption (fasttop) ... help?

H. S. Teoh hsteoh at quickfur.ath.cx
Sun Feb 24 17:39:38 PST 2013


On Sun, Feb 24, 2013 at 03:14:01PM -0800, Charles Hixson wrote:
> Given a struct with:
> 
> ~this()
> {  close();	}
> 
> void	close()
> {  if	(currentKey !is null)	currentKey	=	null;
>    if	(cursor is null)	return;
>    tcbdbcurdel(cursor);
> }
> 
> and:
> 
>   scope (exit)	if (bdb !is null)  tcbdbclose(bdb);
>   //scope(exit)	cur.close;	   // <<- cur is the struct noted above
[...]

The struct dtor is automatically called upon exiting the scope, so your
scope(exit) here is redundant, and is the cause of the double free.


T

-- 
Written on the window of a clothing store: No shirt, no shoes, no service.


More information about the Digitalmars-d-learn mailing list