0

I have built and run the code below as an Android app. The app works a expected but I get a segemtation fault in the TIdSSLIOhandler when closing down. Is the Indy components not compatible with FireMonkey?

unit Main;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, IdIOHandler,
  IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL, IdBaseComponent,
  IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, FMX.Layouts, FMX.Memo,
  FMX.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Memo1: TMemo;
    http: TIdHTTP;
    ioSocket: TIdSSLIOHandlerSocketOpenSSL;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private

    LiServer:string;
    procedure DBCom(var retdata: TStringlist);
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}
{$R *.LgXhdpiPh.fmx ANDROID}

procedure TForm1.Button1Click(Sender: TObject);
var m: TMemoryStream;
    retdata: TStringList;
    i:integer;
begin
  m:=TMemoryStream.Create;

  //--- init data
  retdata:=TStringList.Create;
  retdata.Add('F=1');

  //--- add data
  retdata.Add('Data=1');

  //--- send data to server database
  DBCom(retdata);

  for i := 0 to retdata.Count-1 do
    memo1.Lines.Add(retdata[i]);

  //--- free allocated resources
  retdata.Free;
  m.Free;
end;

procedure TForm1.Button2Click(Sender: TObject);
var m: TMemoryStream;
    retdata: TStringList;
    i:integer;
begin
  m:=TMemoryStream.Create;

  //--- init data
  retdata:=TStringList.Create;
  retdata.Add('F=1');

  //--- add data
  retdata.Add('Data=A');

  //--- send data to server database
  DBCom(retdata);

  for i := 0 to retdata.Count-1 do
    memo1.Lines.Add(retdata[i]);

  //--- free allocated resources
  retdata.Free;
  m.Free;
end;

//============ communication with DB
procedure TForm1.DBCom(var retdata:TStringlist);
var m: TMemoryStream;
    errcode,i,msgid,status,id:Integer;
begin
  m:=TMemoryStream.Create;

  //--- send data to server database
  http.Post(LiServer, retdata, m);
  m.Position:=0;
  retdata.LoadFromStream(m);

  //--- free allocated resources
  m.Free;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  LiServer:='http://server.com/url.php';
end;

end.

The error occurs in this procedure on the SSL_CTX_free(fContext) line.

procedure TIdSSLContext.DestroyContext;
begin
  if fContext <> nil then begin
    SSL_CTX_free(fContext);
    fContext := nil;
  end;
end;
Lars Ljungberg
  • 313
  • 1
  • 6
  • 19
  • 2
    Indy is compatible with FireMonkey and works just fine with it. Even Embarcadero uses Indy in their own cross-platform technologies. What does the error message actually say? What does the call stack look like when the error is raised? I suspect you might be running into the following issue: [AV in TIdStack.DecUsage() in Android 4.4.x](http://code.google.com/p/indyproject/issues/detail?id=291) – Remy Lebeau Nov 17 '14 at 18:17
  • Thanks for the information. Then I know it's safe to continue to use the Indy components. I have updated my post with where I get the segmentation fault. – Lars Ljungberg Nov 18 '14 at 13:59

1 Answers1

0

@Remy Lebeau had given me the answer I was looking for in the note above.

Lars Ljungberg
  • 313
  • 1
  • 6
  • 19