True free heap not what it should be after ShellExecute

338 views Asked by At

I have a simple Application that reads data from an .ini file into a record, and then does a ShellExecute. However, when I run it in debug mode,it tells me that the True free heap isn't what it should be:

"True heap size: 688128, True free heap: 688016, Should be: 688128"

Heaptrc message

This only happens if I actually run the ShellExecute (however even if I don't run the ShellExecute, I get a True free heap of 688016, but no complaint that it should be 688128), so I wonder if I either need to free the PChar() conversion (which shouldn't be the case from all that I've read), or the handle returned by ShellExecute (though CloseHandle(ShellHandle); doesn't change the message), or if it's intended behavior?

The IniSettings.SetupCommand in question is an .msi file that triggers a UAC prompt, but I really just want to make this a Fire & Forget thing since my Lazarus app doesn't care what it launches.

For reference, here's my whole Unit. I'm using Lazarus 1.6.2, FPC 3.0.0, i386-win32, and I'm targeting Windows only with this. My Debug Settings are at the very bottom, after the code.

unit MainUnit;   

{$mode objfpc}{$H+}    

interface    

uses
  Classes, SysUtils, FileUtil, Forms, Controls,
  Graphics, Dialogs, StdCtrls, IniFiles, Windows;

type
  { IniSettings }
  TAutorunIniSettings = record
    AutorunTitle: AnsiString;
    SetupCommand: AnsiString;
  end;

  { TMainForm }
  TMainForm = class(TForm)
    btnSetup: TButton;
    lblTitle: TLabel;
    procedure btnSetupClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { private declarations }
    IniSettings: TAutorunIniSettings;
  public
    { public declarations }
  end;

var
  MainForm: TMainForm;

implementation

{$R *.lfm}

{ TMainForm }

procedure TMainForm.FormCreate(Sender: TObject);
var
  AutorunIni: TIniFile;
begin
  try
    AutorunIni := TIniFile.Create('Autorun.ini');
    IniSettings.AutorunTitle := AutorunIni.ReadString('Autorun', 'Title', 'Autorun');
    IniSettings.SetupCommand := AutorunIni.ReadString('Autorun', 'Setup', '');

    self.Caption := IniSettings.AutorunTitle;
  finally
    if(AutorunIni <> nil) then AutorunIni.Free;
  end;
end;

procedure TMainForm.FormDestroy(Sender: TObject);
begin

end;

procedure TMainForm.btnSetupClick(Sender: TObject);
begin
     ShellExecute(0, 'open', PChar(IniSettings.SetupCommand), nil, nil, SW_SHOWNORMAL);
end;

end.

Lazarus Debug Settings

0

There are 0 answers