Segmentation error at the end problem (148 line program listing)
Charles Hixson
charleshixsn at earthlink.net
Wed Jan 28 13:37:40 PST 2009
Gide Nwawudu wrote:
> On Tue, 27 Jan 2009 22:48:33 -0800, Charles Hixson
> <charleshixsn at earthlink.net> wrote:
>
>> Main routine:
>>
>> void main()
>> {
>> try
>> { BlockFile bf;
>> bf = new BlockFile ("test.bf", 4096);
>> writefln ("before close");
>> bf.close;
>> bf = null;
>> writefln ("after close");
>> BlockFile cf = new BlockFile ("test.bf", 4096);
>> writefln ("after second open");
>> }
>> catch (Exception e)
>> { writefln ("Caught Exception ", e); }
>> }
>>
>> Results in:
>> Exiting BlockFile::this
>> before close
>> after close
>> Exiting BlockFile::this
>> after second open
>> Segmentation fault
>>
>> I could post all the code. It's only 146 lines. But perhaps this is
>> enough?
>
> I'm thinking it might be an issue with close and the dtor being called
> on the same object. If you add std.gc.fullCollect() after the bf =
> null. Does that make the code seg fault before 'after close' is
> written?
>
> Gide
I had to wriggle the code around a bit. (It's D2 not D1.) However it
didn't make any difference to do:
void main()
{
try
{ BlockFile bf;
bf = new BlockFile ("test.bf", 4096);
writefln ("before close");
bf.close;
bf = null;
GC.collect;
writefln ("after close");
BlockFile cf = new BlockFile ("test.bf", 4096);
writefln ("after second open");
}
catch (Exception e)
{ writefln ("Caught Exception ", e); }
}
-------------------
And the docs say that GC.collect does a full collect;
P.S.: Attached is the full listing
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tst2.d
Type: text/x-dsrc
Size: 4729 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20090128/0372b45d/attachment.d>
More information about the Digitalmars-d-learn
mailing list