[fpc-devel] Segmentation fault for Firebird exception inside thread
Stefan
stefan at sss-smart.net
Tue Oct 25 12:23:31 CEST 2011
Hello, this is my first post and I hope this is the correct list for my question.
I'm getting a segmentation fault ('violaciĆ³n de segmento' in spanish)
when running the code from below on a Linux 64-bit machine (OpenSuse 10.2 64-bits).
I'm using FPC 2.2.5, so perhaps the error is already known, but I did not find any solution in the web.
I tested the code on Windows 32 bits and Linux 32 bits too, but there everything seems ok.
The example is about opening a Firebird connection in a thread.
When there is a Firebird exception inside this connection,
the application terminates with the segmentation fault.
Does anyone know about this error, or can anyone give me a hint, where to look for a solution?
This is the example code:
<code>
program fbthreadtest;
{$IFDEF FPC}
{$MODE DELPHI}{$H+}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
cwstring,
{$ENDIF}
Classes,
IBConnection, sqldb;
type
TFBThread = class(TThread)
private
protected
procedure Execute; override;
public
constructor Create;
end;
constructor TFBThread.Create;
begin
inherited Create(True);
FreeOnTerminate := False;
Resume;
end;
procedure TFBThread.Execute;
var
db: TIBConnection;
tr: TSQLTransaction;
q: TSQLQuery;
begin
db := TIBConnection.Create(nil);
try
db.DatabaseName := 'localhost:/home/data/Database/ssstst.gdb';
db.LoginPrompt := False;
db.HostName := '';
db.UserName := 'SYSDBA';
db.Password := 'masterkey';
db.Connected := TRUE;
tr := TSQLTransaction.Create(nil);
try
tr.DataBase := db;
tr.Action := caCommit;
tr.Params.Clear;
tr.Params.Add('isc_tpb_read_committed');
tr.Params.Add('isc_tpb_rec_version');
tr.Params.Add('isc_tpb_nowait');
db.Transaction := tr;
tr.Active := True;
q := TSQLQuery.Create(nil);
try
q.Database := db;
q.Transaction := tr;
try
Writeln('select...');
// the following line raises an exception because rdb$databases doesn't exist.
q.SQL.Text := 'select count(*) from rdb$databases';
q.Prepare;
except
Writeln('...exception');
end;
finally
q.Free;
end;
finally
tr.Commit;
tr.Free;
end;
finally
db.Connected := False;
db.Free;
end;
end;
begin
with TFBThread.Create do begin
WaitFor;
Free;
end;
end.
</code>
Thanks,
Stefan
More information about the fpc-devel
mailing list