Jump to content
alogrep

Madexcept leaks show false positives?

Recommended Posts

Hi.
I tried to open to the Madexcept forum, but I get a FORBIDDEN response.
So, I'll kindly ask here.
Are these cases false positive leaks :


Case 1:

    this line line is listed in the report
    if (copy(thisip, 1, 7) <> '192.168') and (pos('127.0.', thisip) <> 1) then
Case 2:
  resultcode := ProcessHttpRequest(method, uri, protocol, ss, keepalive,
      nosettype, linkclose);
  and this is the declaration of ProcessHttpRequest

     function ProcessHttpRequest(Request, uri, protocol, params: string;
      var keepalive: boolean; var nosettype, linkclose: boolean): integer;

Case 3:
   everywhere I use the degub() procedure, Madexcept lists the line as a leak
    e.g. debug('ADQUIRE '+ formatdatetime('HH:NN:SS:ZZZ',Now));

 

procedure debug(s: string);
VAR
  I: integer;
begin
  if (debughook <> 0) OR inparams('Z', I) then
  begin
    writeln(F1, s);
    flush(F1);
  end;

I also see a line "WritetoStream is not supported  by TnxCallbackFilterOptioins, but I have no idea to what unit/line of code it refers to.

Finally, in the upper pane of the eport I see lsited all the lines that I used to create a stringlist  to form a html markup to be transferred: why ? what does it mean?

(I attached the report)

Thanks for any help.
 

Posserver.exe - 2025-08-25 - 16.31.13 - leak report.mbr

Edited by Lars Fosdal
fixed typo in title

Share this post


Link to post

Hi,

8 hours ago, alogrep said:

Are these cases false positive leaks :

They doesn't look like that, looks innocent.

 

What is really strange and make no sense at all is the log you attached, take an example this one

thread $34f0 (TTCPHttpThrd):
7a26999b madExcept32.dll madExceptDbg     1773 GetMemCallback
006973f0 Posserver.exe   System           4966 @GetMem
0069c5fa Posserver.exe   System          26079 @NewUnicodeString
0069c83b Posserver.exe   System          26693 @UStrFromPWCharLen
0069c912 Posserver.exe   System          26870 InternalUStrFromPCharLen
006973f0 Posserver.exe   System           4966 @GetMem
0069c5fa Posserver.exe   System          26079 @NewUnicodeString
0069d6af Posserver.exe   System          31391 @UStrSetLength
006f2771 Posserver.exe   System.SysUtils  8486 _IntToStr32
006f2aa8 Posserver.exe   System.SysUtils  8601 IntToStr
006f52f8 Posserver.exe   System.SysUtils 13425 WideFormatBuf
006f584b Posserver.exe   System.SysUtils 13565 WideFormatBuf
006a3437 Posserver.exe   System          41854 LocaleCharsFromUnicode
006983f7 Posserver.exe   System          11904 TextOut
0069c5fa Posserver.exe   System          26079 @NewUnicodeString
00ea26a4 Posserver.exe   http             3486 TTCPHttpThrd.ProcessHttpRequest
006f49a0 Posserver.exe   System.SysUtils 12905 FormatBuf
006f4981 Posserver.exe   System.SysUtils 12898 FormatBuf
006f6f9f Posserver.exe   System.SysUtils 20007 AppendNumber
006f6f41 Posserver.exe   System.SysUtils 19991 AppendChars
006f7b98 Posserver.exe   System.SysUtils 20444 AppendFormat
006f7c31 Posserver.exe   System.SysUtils 20449 DateTimeToString
006f7d67 Posserver.exe   System.SysUtils 20460 DateTimeToString
006973f0 Posserver.exe   System           4966 @GetMem
00e94450 Posserver.exe   http             1155 TTCPHttpThrd.ProcessHttpRequest
00e805f0 Posserver.exe   http              622 TTCPHttpThrd.Execute
007505a1 Posserver.exe   madExcept             CallThreadProcSafe
00750606 Posserver.exe   madExcept             ThreadExceptFrame
006f6943 Posserver.exe   System.SysUtils 19661 TryEncodeTime                      <------
006f697e Posserver.exe   System.SysUtils 19668 EncodeTime
006f6e1b Posserver.exe   System.SysUtils 19871 Now
006f7dd3 Posserver.exe   System.SysUtils 20518 FormatDateTime
00e945b0 Posserver.exe   http             1174 TTCPHttpThrd.ProcessHttpRequest
00e945ef Posserver.exe   http             1174 TTCPHttpThrd.ProcessHttpRequest
00ea26a4 Posserver.exe   http             3486 TTCPHttpThrd.ProcessHttpRequest
00e805f0 Posserver.exe   http              622 TTCPHttpThrd.Execute
00e80a16 Posserver.exe   http              673 TTCPHttpThrd.Execute
007506bb Posserver.exe   madExcept             HookedTThreadExecute
00750726 Posserver.exe   madExcept             HookedTThreadExecute
007dd4d9 Posserver.exe   System.Classes  16396 ThreadProc
007505a1 Posserver.exe   madExcept             CallThreadProcSafe
00750606 Posserver.exe   madExcept             ThreadExceptFrame
0075067c Posserver.exe   madExcept             ThreadExceptFrame
007506bb Posserver.exe   madExcept             HookedTThreadExecute
00750726 Posserver.exe   madExcept             HookedTThreadExecute
006973f0 Posserver.exe   System           4966 @GetMem
0069c5fa Posserver.exe   System          26079 @NewUnicodeString
0069d6af Posserver.exe   System          31391 @UStrSetLength
00701456 Posserver.exe   System.SysUtils 30732 TStringHelper.Create
006f7d18 Posserver.exe   System.SysUtils 20459 DateTimeToString
006f7d67 Posserver.exe   System.SysUtils 20460 DateTimeToString
006973f0 Posserver.exe   System           4966 @GetMem
00e94450 Posserver.exe   http             1155 TTCPHttpThrd.ProcessHttpRequest
00e805f0 Posserver.exe   http              622 TTCPHttpThrd.Execute
007505a1 Posserver.exe   madExcept             CallThreadProcSafe
00750606 Posserver.exe   madExcept             ThreadExceptFrame
00eac77b Posserver.exe   misc              262 html2sg                                 <------
00e98c33 Posserver.exe   http             1981 TTCPHttpThrd.ProcessHttpRequest
00e805f0 Posserver.exe   http              622 TTCPHttpThrd.Execute
007506bb Posserver.exe   madExcept             HookedTThreadExecute
007dd4d9 Posserver.exe   System.Classes  16396 ThreadProc
0069c548 Posserver.exe   System          25850 ThreadWrapper
007505a1 Posserver.exe   madExcept             CallThreadProcSafe
00750606 Posserver.exe   madExcept             ThreadExceptFrame
7649fcc7 KERNEL32.DLL                          BaseThreadInitThunk

What do we see ?

TTCPHttpThrd.ProcessHttpRequest behave like recursive !! but no it is not recursive, yet walking the call stack is illogical,

html2sg does raise an exception ? or it doesn't ?, the exception most likely is handled inside try..except..end clause, yet two calls after that come from madexcept then the stack point to TTCPHttpThrd.Execute, that is unexplainable 

Also TryEncodeTime is raising an exception !? or not ?

No need to answer the above, as the log might be wrong.

 

I am not expert with madexcept, but i want to point that you might be miss configured it and caused this reports, so if you asked it to capture handled exception then it might be the cause, but i am not sure.

 

As suggestion, start with the simplest thing which is make sure to pass strings as const in these two

     function ProcessHttpRequest(const Request, uri, protocol, params: string;
      var keepalive: boolean; var nosettype, linkclose: boolean): integer;

procedure debug(const s: string);
VAR
  I: integer;
begin
  if (debughook <> 0) OR inparams('Z', I) then
  begin
    writeln(F1, s);
    flush(F1);
  end;

In case your code failed to compile then just add local strings and load the content form the parameters, this easily could be the solution for the above unexplained madexcept log.

 

Suggestion Fix the declaration to const and try to change/tweak madexcept behavior then capture a new log then share, in case the problem persist.

 

and Good luck!

Share this post


Link to post

Thanks, Kas.

Firstly, passing string as const made no difference.

as to the ProcessHttpRequest that looks as recursive, it is not recursive, but it is a thread that is created almost continually.

The app is an HTTP server:

 repeat
          if _stopdeamon or terminated then break;
          try
            b:= canread (1000);
          except
            on E:SysUtils.Exception do begin
              debug('****** Canread error: '+e.message);
            end;
          end;
          if b then begin
              if _stopdeamon then
                  exit;
              ClientSock:=sock.accept;
             n:= lastError;
             if (n=0) then begin
               try
                 TTCPHttpThrd.create(ClientSock);
               except
                on E:SysUtils.Exception do begin
                  debug('TTCPHttpThrd.create ERROR: '+e.message);
                end;
               end;
             end else
                debug('lasterror='+sock.GetErrorDesc(n));
          end;
        until false;

and it is defined here:

 TTCPHttpThrd = class(TThread)
  private
    Sock:TTCPBlockSocket;
    TrayIconData: TNotifyIconData;
    .....
    ...... 
  public

    Constructor Create (hsock:tSocket);
    Destructor Destroy; override;
    procedure Execute; override;
    function ProcessHttpRequest(Request, URI,protocol,params: string; var keepalive:boolean; var nosettype,linkclose: boolean): integer;
   
  end;

It lloks like somehow madexcept gets "confused" with string, AnsiString and Unicodestring. I only use string or AnsiString in the code (is Ansistring the default?).  but the most inexcplicalbe this is that madexcept show a leak here:

 

if (copy(thisip, 1, 7) <> '192.168') and (pos('127.0.', thisip) <> 1) then

And also for this line

     debug('ADQUIRE ' + FormatDateTime('HH:NN:SS:ZZZ', NOW));

the repot shows the leak twice:, see attached l.jpg

l.jpg

Share this post


Link to post
13 hours ago, alogrep said:

It lloks like somehow madexcept gets "confused" with string, AnsiString and Unicodestring. I only use string or AnsiString in the code (is Ansistring the default?).  but the most inexcplicalbe this is that madexcept show a leak here:

 


if (copy(thisip, 1, 7) <> '192.168') and (pos('127.0.', thisip) <> 1) then

And also for this line

     debug('ADQUIRE ' + FormatDateTime('HH:NN:SS:ZZZ', NOW));

Not exactly confused as much it is catching the temporary string, see the common thing between these worrying lines is the temp string, Copy will generate temp string, like the concatenation with "+", to confirm this extract these into their own declared string var then put that var in-place to see if the report change.

 

That is little problem, the problem i am afraid of is the unreadable and none sense stack trace, take as example TryEncodeTime i mentioned earlier, it is low level and has should not raise exception, also it is end point, meaning it should never ever seen at a stack unless it raised an exception or in this very case and because we (madexcept) are tracking memory allocation, it should be ended with the real memory allocation, that is not what reported, as madexcept call trace shows it passed ProcessHttpRequest, this makes no sense, pointing that the call trace (stack) is wrong and not trust worthy, madexcept failed to build clean stack trace.

There is also a temp string introduced by compiler every time you use or pass different string type, like concatenation a Ansistring with different string type, so it could be "thisip" is declared an Ansi on newer Delphi while pos will force the compiler to do the temp conversion..

Also TryEncodeTime is allocating temp string to pass it as result (out to be exact and not result), so it really could like the first lines i wrote the cause is failure to handle tempstring that compiler is generating behind the scene.

 

Anyway, these all may be false positive as you asked, but the shuffled stack makes me afraid from sinister behavior coming form madexcept, is this is missed up and broken then what else ?!

 

Didn't mention what Delphi you are using and if madexcept is up to date, and i really think it is miss configuration in madexcept or a bug, but has little to do with Delphi, unless you are using Delphi version that is not supported by your madexcept.

Share this post


Link to post

madExcept is known to have really solid stack trace capabilities so it does seem very likely that it's a mis-configuration rather than any issue with madExcept or Delphi

Share this post


Link to post

The call stacks are bogus - some entries below WideFormatBuf is incorrect - System.LocaleCharsFromUnicode never calls System.SysUtils.WideFormatBuf - but FormatBuf does.

Then some entries below DateTimeToString are incorrect - it most likely was called from TryEncodeTime

Edited by Stefan Glienke

Share this post


Link to post

Well looking at the log again, i see it differently, and it is madexcept fault, 

 

the first log is nice 

main thread ($24b0):
7a26999b madExcept32.dll madExceptDbg  1773 GetMemCallback
006973f0 Posserver.exe   System        4966 @GetMem
0069c5fa Posserver.exe   System       26079 @NewUnicodeString
0069c83b Posserver.exe   System       26693 @UStrFromPWCharLen
0069d93e Posserver.exe   System       32005 @UStrCopy
00ec5dc6 Posserver.exe   DEFSa         2399 LOADTRANSLATIONS
00ec5e59 Posserver.exe   DEFSa         2408 LOADTRANSLATIONS
00ec5e98 Posserver.exe   DEFSa         2413 LOADTRANSLATIONS
00eaa910 Posserver.exe   Unitmain       678 TMain.FormCreate
00eaacff Posserver.exe   Unitmain       740 TMain.FormCreate
009134d5 Posserver.exe   Vcl.Forms     5534 TCustomForm.DoCreate
00912ff4 Posserver.exe   Vcl.Forms     5401 TCustomForm.AfterConstruction
0069ae25 Posserver.exe   System       19736 @AfterConstruction
00912fb0 Posserver.exe   Vcl.Forms     5391 TCustomForm.Create
00920a12 Posserver.exe   Vcl.Forms    13527 TApplication.CreateForm
00ee3510 Posserver.exe   Posserver      132 initialization
7649fcc7 KERNEL32.DLL                       BaseThreadInitThunk

It end with GetMem as it should, but include GetMemCallBack which is the hook for madexcept, and i am not familiar with madexcept, but i think the reasonable action is to strip the hook.

In any case the log is nice, 

 

Later it lose control, as all these stack traces should be ended with either GetMem or ReallocMem, and be deleted form record later when FreeMem being called on the same address,

Yet in the middle of that log, we see it start to count two or three GetMem before stopping, in the end of the log file ( the most later entries) it looks like it hit hard point to continue and stop

 This one from the middle 

7a26999b madExcept32.dll madExceptDbg     1773 GetMemCallback
006973f0 Posserver.exe   System           4966 @GetMem                              <-----------
0069c5fa Posserver.exe   System          26079 @NewUnicodeString
0069c83b Posserver.exe   System          26693 @UStrFromPWCharLen
0069c912 Posserver.exe   System          26870 InternalUStrFromPCharLen
006973f0 Posserver.exe   System           4966 @GetMem                              <-----------
0069c5fa Posserver.exe   System          26079 @NewUnicodeString
0069d6af Posserver.exe   System          31391 @UStrSetLength
006f2771 Posserver.exe   System.SysUtils  8486 _IntToStr32
006f2aa8 Posserver.exe   System.SysUtils  8601 IntToStr
006f52f8 Posserver.exe   System.SysUtils 13425 WideFormatBuf
006f584b Posserver.exe   System.SysUtils 13565 WideFormatBuf
006a3437 Posserver.exe   System          41854 LocaleCharsFromUnicode
006983f7 Posserver.exe   System          11904 TextOut
0069c5fa Posserver.exe   System          26079 @NewUnicodeString
00ea26a4 Posserver.exe   http             3486 TTCPHttpThrd.ProcessHttpRequest
006f49a0 Posserver.exe   System.SysUtils 12905 FormatBuf
006f4981 Posserver.exe   System.SysUtils 12898 FormatBuf
006f6f9f Posserver.exe   System.SysUtils 20007 AppendNumber
006f6f41 Posserver.exe   System.SysUtils 19991 AppendChars
006f7b98 Posserver.exe   System.SysUtils 20444 AppendFormat
006f7c31 Posserver.exe   System.SysUtils 20449 DateTimeToString
006f7d67 Posserver.exe   System.SysUtils 20460 DateTimeToString
006973f0 Posserver.exe   System           4966 @GetMem                              <-----------
00e94450 Posserver.exe   http             1155 TTCPHttpThrd.ProcessHttpRequest
00e805f0 Posserver.exe   http              622 TTCPHttpThrd.Execute
007505a1 Posserver.exe   madExcept             CallThreadProcSafe
00750606 Posserver.exe   madExcept             ThreadExceptFrame
006f6943 Posserver.exe   System.SysUtils 19661 TryEncodeTime
006f697e Posserver.exe   System.SysUtils 19668 EncodeTime
006f6e1b Posserver.exe   System.SysUtils 19871 Now
006f7dd3 Posserver.exe   System.SysUtils 20518 FormatDateTime
00e945b0 Posserver.exe   http             1174 TTCPHttpThrd.ProcessHttpRequest
00e945ef Posserver.exe   http             1174 TTCPHttpThrd.ProcessHttpRequest
00ea26a4 Posserver.exe   http             3486 TTCPHttpThrd.ProcessHttpRequest
00e805f0 Posserver.exe   http              622 TTCPHttpThrd.Execute
00e80a16 Posserver.exe   http              673 TTCPHttpThrd.Execute
007506bb Posserver.exe   madExcept             HookedTThreadExecute
00750726 Posserver.exe   madExcept             HookedTThreadExecute
007dd4d9 Posserver.exe   System.Classes  16396 ThreadProc
007505a1 Posserver.exe   madExcept             CallThreadProcSafe
00750606 Posserver.exe   madExcept             ThreadExceptFrame
0075067c Posserver.exe   madExcept             ThreadExceptFrame
007506bb Posserver.exe   madExcept             HookedTThreadExecute
00750726 Posserver.exe   madExcept             HookedTThreadExecute
006973f0 Posserver.exe   System           4966 @GetMem                              <-----------
0069c5fa Posserver.exe   System          26079 @NewUnicodeString
0069d6af Posserver.exe   System          31391 @UStrSetLength
00701456 Posserver.exe   System.SysUtils 30732 TStringHelper.Create
006f7d18 Posserver.exe   System.SysUtils 20459 DateTimeToString
006f7d67 Posserver.exe   System.SysUtils 20460 DateTimeToString
006973f0 Posserver.exe   System           4966 @GetMem                              <----------- shoudl stopped here
00e94450 Posserver.exe   http             1155 TTCPHttpThrd.ProcessHttpRequest
00e805f0 Posserver.exe   http              622 TTCPHttpThrd.Execute
007505a1 Posserver.exe   madExcept             CallThreadProcSafe
00750606 Posserver.exe   madExcept             ThreadExceptFrame
00eac77b Posserver.exe   misc              262 html2sg
00e98c33 Posserver.exe   http             1981 TTCPHttpThrd.ProcessHttpRequest
00e805f0 Posserver.exe   http              622 TTCPHttpThrd.Execute
007506bb Posserver.exe   madExcept             HookedTThreadExecute
007dd4d9 Posserver.exe   System.Classes  16396 ThreadProc
0069c548 Posserver.exe   System          25850 ThreadWrapper
007505a1 Posserver.exe   madExcept             CallThreadProcSafe
00750606 Posserver.exe   madExcept             ThreadExceptFrame
7649fcc7 KERNEL32.DLL                          BaseThreadInitThunk

Now that make sense at least from me.

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×