scope(exit) & stack => double free or corruption (fasttop) ... help?
Charles Hixson
charleshixsn at earthlink.net
Mon Feb 25 22:21:50 PST 2013
On 02/24/2013 05:39 PM, H. S. Teoh wrote:
> 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
>
Sorry, but that wasn't the answer...which was trivial, when I saw it. I
needed to change the close() routine to:
void close()
{ if (currentKey !is null) currentKey = null;
if (cursor is null) return;
tcbdbcurdel(cursor);
cursor = null;
}
Apparently the library didn't null the cursor after it closed (deleted) it.
More information about the Digitalmars-d-learn
mailing list