Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-04

TFilestream raises exception class 'External SIGSEGV'

8 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Dave Coventry

Hi, I'm having a problem with the following code:

  Fstr:=TFileStream.Create('data',fmOpenRead);
  i:=0;
  while i<Fstr.Size do
  begin
    b:=Fstr.ReadByte;
    inc(i);
   ............. Stuff ......................
  end;
  Fstr.Free;  <-- Exception raised here

Do TFileStream objects not have to be freed?

Lazarus version: v0.9.27 r i386-win32-win32/win64
Date 2009-03-19
FPC Version 2.2.2

Reply by email

JoshyFun
to Dave Coventry

Hello General,

Tuesday, April 14, 2009, 3:16:13 PM, you wrote:

DC>   Fstr:=TFileStream.Create('data',fmOpenRead);
DC>   i:=0;
DC>   while i<Fstr.Size do
DC>   begin
DC>     b:=Fstr.ReadByte;
DC>     inc(i);
DC>    ............. Stuff ......................
DC>   end;
DC>   Fstr.Free;  <-- Exception raised here

DC> Do TFileStream objects not have to be freed?

Quite sure you are trashing the stack in the "....stuff...." part, maybe an array access ? Pointers ? Do you have range checking enabled ?

In the other hand, use of a TFileStream to read byte by byte is overkill.

Best regards, JoshyFun

Reply by email

waldo kitty
to Dave Coventry: Hi, I'm having a problem with the following code:…
Dave Coventry wrote 13 lines
Hi, I'm having a problem with the following code: Fstr:=TFileStream.Create('data',fmOpenRead); i:=0; while i<Fstr.Size do begin b:=Fstr.ReadByte; inc(i); ............. Stuff ...................... end; Fstr.Free; <-- Exception raised here Do TFileStream objects not have to be freed?

did you close Fstr after the while loop? the above doesn't show it...

NOTE: NEW EMAIL ADDRESS!! _\/ (@@) Waldo Kitty, Waldo's Place USA __ooO_( )_Ooo_____________________ telnet://bbs.wpusa.dynip.com _|_____|_____|_____|_____|_____|_____ http://www.wpusa.dynip.com ____|_____|_____|_____|_____|_____|____ ftp://ftp.wpusa.dynip.com _|_Eat_SPAM_to_email_me!_YUM!__|_____ wkitty42 -at- windstream.net

Reply by email

Dave Coventry
to JoshyFun: DC> Fstr:=TFileStream.Create('data',fmOpenRead); DC> i:=0; DC> while i<Fstr.Size do…

Hi JoshyFun,

Thanks for taking the time.

2009/4/14 JoshyFun :

Quite sure you are trashing the stack in the "....stuff...." part, maybe an array access ? Pointers ? Do you have range checking enabled

Could be, but I'm just adding items to a dynamic array.

In the other hand, use of a TFileStream to read byte by byte is overkill.

True, but I'm going through the file looking for a particular character $1B and assigning data to different dynamic arrays based on the byte following the <ESC> byte.

Reply by email

Dave Coventry
to Sergei Gorelkin: TFileStream's have to be freed. Your problem is most probably caused by memory corruption…

2009/4/14 Sergei Gorelkin :

Show quoted text 5 lines
TFileStream's have to be freed. Your problem is most probably caused by memory corruption somewhere in the skipped part of code. Once the heap is corrupt, any operation that involves allocating or freeing memory may end up with a random fault (but most often, with a SIGSEGV).

Okay, thanks, I'll have a look at that section of the code then.

Reply by email

Dave Coventry
to waldo kitty: did you close Fstr after the while loop? the above doesn't show it... NOTE: NEW EMAIL…

Thanks for all the suggestions.

It was indeed nothing to do with the code I'd posted but had to do
with a subroutine which added elements to a dynamic array.

I rewrote the subroutine and it now works fine.

2009/4/14 waldo kitty :

Show quoted text 31 lines
Dave Coventry wrote: > Hi, I'm having a problem with the following code: > > ? Fstr:=TFileStream.Create('data',fmOpenRead); > ? i:=0; > ? while i<Fstr.Size do > ? begin > ? ? b:=Fstr.ReadByte; > ? ? inc(i); > ? ?............. Stuff ...................... > ? end; > ? Fstr.Free; ?<-- Exception raised here > > Do TFileStream objects not have to be freed? did you close Fstr after the while loop? the above doesn't show it... -- NOTE: NEW EMAIL ADDRESS!! ? ? ? ?_\/ ? ? ? (@@) ? ? ? ? ? ? ? ? ? ? ?Waldo Kitty, Waldo's Place USA __ooO_( )_Ooo_____________________ telnet://bbs.wpusa.dynip.com _|_____|_____|_____|_____|_____|_____ http://www.wpusa.dynip.com ____|_____|_____|_____|_____|_____|____ ftp://ftp.wpusa.dynip.com _|_Eat_SPAM_to_email_me!_YUM!__|_____ wkitty42 -at- windstream.net _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

JoshyFun
to Dave Coventry: Thanks for taking the time. 2009/4/14 JoshyFun : Could be, but I'm just adding items to a…

Hello Dave,

you wrote
> In the other hand, use of a TFileStream to read byte by byte is > overkill.

DC> True, but I'm going through the file looking for a particular DC> character $1B and assigning data to different dynamic arrays based on DC> the byte following the <ESC> byte.

Anyway, use some kind of cache, each read operation involves a complete read from disk (disk cache mostly) and a transition between user mode to kernel mode and viceversa. Using a simple 4 Kb cache will raise the performance 100 or 1000 times.

Best regards, JoshyFun

Reply by email