• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 

Memory corruption/leak in nrComm open/close

Started by Sandor Dobi, June 10, 2012, 02:41:11 pm

Previous topic - Next topic

Sandor Dobi

June 10, 2012, 02:41:11 pm Last Edit: June 10, 2012, 02:48:29 pm by Sandor Dobi
Hi,

The FastMM4 found a memory problem with the nrComm component activate/deactive.


When you activate first time the port it is done without error. But if after that I deactivate it and activate it again  I getting the following error:

I Use Delphi XE2 Update3. Dont want to get Update4 because I need reinstall everything.

I tried this with nrCommLib v9.29 and v9.30 PRO versions and both contains the problem.

FastMM has detected an error during a GetMem operation. FastMM detected that a block has been modified after being freed.

Modified byte offsets (and lengths): 72(8)

The previous block size was: 100

This block was previously allocated by thread 0x15A4, and the stack trace (return addresses) at the time was:
4046FA [System][@GetMem]
405137 [System][TObject.NewInstance]
4057A6 [System][@ClassCreate]
51C249 [nrcomm][TCommThread.$bctr]
51C3CF [nrcomm][TMsgThread.$bctr]
51CBDB [nrcomm][TnrCustomComm.ThreadStart]
51CAC8 [nrcomm][TnrCustomComm.Open]
7293A505 [Unknown function at SetWindowThemeAttribute]
518A9D [nrclasses][TnrBaseIO.SetActive]
51EF7D [uMain.pas][uMain][TForm1.Button1Click][30]
48B1D1 [Vcl.Controls][Controls.TControl.Click]

The block was previously used for an object of class: TCommThread

The allocation number was: 802

The block was previously freed by thread 0x14E0, and the stack trace (return addresses) at the time was:
404716 [System][@FreeMem]
405155 [System][TObject.FreeInstance]
4057F1 [System][@ClassDestroy]
4550BA [System.Classes][Classes.TThread.$bdtr]
40519B [System][TObject.Free]
454EE9 [System.Classes][Classes.ThreadProc]
406C7E [System][@SystemThreadWrapper]
755D3677 [BaseThreadInitThunk]
77E59F42 [Unknown function at RtlInitializeExceptionChain]
77E59F15 [Unknown function at RtlInitializeExceptionChain]

The current thread ID is 0x15A4, and the stack trace (return addresses) leading to this error is:
411711 [FastMM4.pas][FastMM4][DebugGetMem][8641]
4046FA [System][@GetMem]
405137 [System][TObject.NewInstance]
4057A6 [System][@ClassCreate]
51C249 [nrcomm][TCommThread.$bctr]
51C3CF [nrcomm][TMsgThread.$bctr]
51CBDB [nrcomm][TnrCustomComm.ThreadStart]
51CAC8 [nrcomm][TnrCustomComm.Open]
7293A505 [Unknown function at SetWindowThemeAttribute]
518A9D [nrclasses][TnrBaseIO.SetActive]
51EF7D [uMain.pas][uMain][TForm1.Button1Click][30]



The sample code is very simple and 100% can be reproduced.

You need a VCL Forms application.
Put a button on a form and a nrComm component.
Set up the nrComm component to a valid portnumber.
Put the button1.onclick event as it in the following code.
Set FastMM4 for fulldebugmode, and for checking the blocks for corruption (NOT checking for interface corruption)
Press the button and volia!


unit uMain;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, nrclasses,
  nrcomm;

type
  TForm1 = class(TForm)
    nrComm1: TnrComm;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
    nrComm1.Active := not nrComm1.Active ;
    if nrComm1.Active then begin
       Button1.Caption := 'Close port' ;
    end
    else begin
       Button1.Caption := 'Open port' ;
    end;
end;

end.


Roman Novgorodov

July 13, 2012, 03:57:23 am #1 Last Edit: July 13, 2012, 04:02:12 am by Roman Novgorodov
Hello

Sorry if my reply is too late. We have problems with email notifications about forum posts.

We tested code with following line of code:

initialization
  ReportMemoryLeaksOnShutdown := true;


All works fine, there are no any leaks.

Please clarify following:

1) Do you use built-in XE2 fastmm or external latest version form sourceforge?
2) What options (directives) do you use?

Better if you will upload here sources of test project.

Roman Novgorodov
DeepSoftware llc
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.