Crash on exit using std.stream.File.

Jb gamezelda2 at gmail.com
Wed Jun 29 14:05:00 PDT 2011


The following piece of code seems to crash consistently on Windows (but it
seems to also affect Linux, and that's where I found it - particularly, it only
seemed to crash depending on the content of a static constructor: removing
almost any line from it removed the crash; the minimal test case was large, so
I have not included it).

import std.stream;
import std.stdio;

class X
{
     Stream output;

     this(Stream output)
     {
          this.output = output;
     }

     void close()
     {
           output.close();
     }

     ~this()
     {
          close();
     }
}

int main(string[] args)
{
     new X(new std.stream.File("x.log", FileMode.OutNew));
     return 0;
}

Adding "writeln(output.isOpen);" to the close() method removes the crash (and
returns true before .close() and false after .close(), as one would expect). On
the large test case for Linux, however, the crash persisted even with isOpen(),
and just "touching" the object crashed the program (it looked like I was
working with an already released object).

PS: Excuse me if I didn't follow all rules for reporting bugs, or if I'm
missing something obvious. But the code is pretty simple and I can't think
about any obvious cause.


More information about the Digitalmars-d-bugs mailing list