FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Segmentation fault in linux

 
Post new topic   Reply to topic     Forum Index -> General
View previous topic :: View next topic  
Author Message
nik



Joined: 28 Feb 2007
Posts: 4

PostPosted: Wed Feb 28, 2007 11:15 am    Post subject: Segmentation fault in linux Reply with quote

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
View user's profile Send private message
Bradley Smith



Joined: 20 Jun 2006
Posts: 60

PostPosted: Thu Mar 01, 2007 12:51 am    Post subject: Re: Segmentation fault in linux Reply with quote

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
View user's profile Send private message
nik



Joined: 28 Feb 2007
Posts: 4

PostPosted: Thu Mar 01, 2007 3:09 am    Post subject: Reply with quote

thanks, now it works
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> General All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group