View previous topic :: View next topic |
Author |
Message |
nik
Joined: 28 Feb 2007 Posts: 4
|
Posted: Wed Feb 28, 2007 11:15 am Post subject: Segmentation fault in linux |
|
|
My problem is that i get a segmentation fault in linux and I can't think of a reason. Look at the code:
Code: |
...
void main( char[][] args )
{
...
writefln( "Hello World" );
// <-- the error occurs here
}
|
when debugging, the following text is shown:
Code: |
(gdb) step
_Dmain (args=578751138103296002) at main.d:25
25 writefln( "Das ist ein Test." );
(gdb) step
Das ist ein Test.
26 }
(gdb) step
0x0804dcc3 in main ()
(gdb) step
Single stepping until exit from function main,
which has no line number information.
Program received signal SIGSEGV, Segmentation fault.
0x08054c9a in _D3std6stream12FilterStream5flushMFZv ()
|
From the last line I follow that it has something to do with the BufferedFile-class I instantiied. The code looks like that:
Code: |
class Test
{
...
Stream ein;
this()
{
ein = new BufferedFile( filename );
}
this() // destructor
{
ein.close
}
}
|
I hope you can help me! Thanks and sorry for my bad english! |
|
Back to top |
|
|
Bradley Smith
Joined: 20 Jun 2006 Posts: 60
|
Posted: Thu Mar 01, 2007 12:51 am Post subject: Re: Segmentation fault in linux |
|
|
You can't use the "ein" object in the destructor. It is a garbage collected object and the reference is no longer valid.
From http://www.digitalmars.com/d/class.html#destructors
Quote: | When the garbage collector calls a destructor for an object of a class that has members that are references to garbage collected objects, those references are no longer valid. This means that destructors cannot reference sub objects. This rule does not apply to auto objects or objects deleted with the DeleteExpression. |
|
|
Back to top |
|
|
nik
Joined: 28 Feb 2007 Posts: 4
|
Posted: Thu Mar 01, 2007 3:09 am Post subject: |
|
|
thanks, now it works |
|
Back to top |
|
|
|