Tatdll memory leak...

Hello,



Version 6.5.2



I started looking into calling a DLL in a script.

I copied the example, from the user manual:



function MessageBox(hwnd: pointer; text, caption: string; msgtype:

integer): integer; stdcall; external 'User32.dll' name 'MessageBoxA';



and pasted it into a script, complied the script, all good.



When I ended the program I get a memory leak for Tatdll and a string.



Is there something I need to do to stop the leak?



Regards,



Mark

Running the provided demo that calls the same method, using ReportMemoryLeaksOnShutDown, I don't get any memory leaks. So maybe it's something in your code? Could you provide the code you are using and the exact memory leak report so we can get a clue on what could be going on?

Here is an example that generates a leak.



Select the leak button, then the close button and I get:



An unexpected memory leak has occurred. The unexpected small block leaks are

21 - 28 bytes: TatDLL x1

69 - 76 bytes: UnicodeString x1



The source file followed by the dfm file.



Source:



unit Main;



interface



uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, atScript, atPascal,Vcl.ScripterInit;



type

TForm1 = class(TForm)

    atPascalScripter1: TatPascalScripter;

    LeakBtn: TButton;

    CloseBtn: TButton;

    procedure LeakBtnClick(Sender: TObject);

    procedure FormCreate(Sender: TObject);

    procedure CloseBtnClick(Sender: TObject);

end;



var

Form1: TForm1;



implementation



{$R *.dfm}



procedure TForm1.CloseBtnClick(Sender: TObject);

begin

Close;

end;



procedure TForm1.FormCreate(Sender: TObject);

begin

ReportMemoryLeaksOnShutdown:=true;

end;



procedure TForm1.LeakBtnClick(Sender: TObject);

var

s1:string;

aScript:TatScript;

begin

atPascalScripter1.AllowDLLCalls:=true;



s1:='function MessageBox(hwnd: pointer; text, caption: string; msgtype:'+ #13#10+

     'integer): integer; stdcall; external ''User32.dll'' name ''MessageBoxA'';'+ #13#10;



try

aScript:=atPascalScripter1.Scripts.Add;

aScript.SourceCode.Text:=s1;

aScript.Compile;

aScript.SelfRegisterAsLibrary(atPascalScripter1,'');

finally

end;

end;



end.



DFM:



object Form1: TForm1

Left = 441

Top = 177

Caption = 'Form1'

ClientHeight = 306

ClientWidth = 513

Color = clBtnFace

Font.Charset = DEFAULT_CHARSET

Font.Color = clWindowText

Font.Height = -11

Font.Name = 'Tahoma'

Font.Style = []

OldCreateOrder = False

OnCreate = FormCreate

PixelsPerInch = 96

TextHeight = 13

object LeakBtn: TButton

    Left = 224

    Top = 80

    Width = 75

    Height = 25

    Caption = 'Leak'

    TabOrder = 0

    OnClick = LeakBtnClick

end

object CloseBtn: TButton

    Left = 224

    Top = 111

    Width = 75

    Height = 25

    Caption = 'Close'

    TabOrder = 1

    OnClick = CloseBtnClick

end

object atPascalScripter1: TatPascalScripter

    SaveCompiledCode = False

    ShortBooleanEval = False

    LibOptions.SearchPath.Strings = (

      '$(CURDIR)'

      '$(APPDIR)')

    LibOptions.SourceFileExt = '.psc'

    LibOptions.CompiledFileExt = '.pcu'

    LibOptions.UseScriptFiles = False

    CallExecHookEvent = False

    Left = 48

    Top = 40

end

end



We were able to reproduce and fix the problem. Please send us an e-mail to our support so we can send you the patch. Wagner R. Landgraf2017-05-22 20:46:34