#1 2024-11-10 20:13:07

rudiloos
Member
From: South Africa
Registered: 2018-11-21
Posts: 6

TSynDaemon/TSynDaemonSettings memory leak

Hi

Busy writing a little server and wanting to put on a Linux machine.
I already have 2 daemons running that was compiled around 2.2.7700 on the main server but never checked for leaks.
Not sure if they have leaks when they are shutdown as they are compiled as releases.
However they also show leaks when compiling them with report memory leaks.

For simplicity I then used the standard Project05Daemon sample to confirm, and this is what these results are based on.

For testing I am running the server with the /verbose and --verbose parameters.
I assume that is what it is there for.

Keep on getting memory leaks for the above mentioned items.
Upgraded to 2.3.8854 (Today) and the results are the same.
Mormot2Tests runs clean.

Leaks for Win32, Win64, Linux 64 with similar outputs. (one 6 blocks the other 5 blocks etc)

Tried to step through the code but the leak only appears after the server actually shuts down
and I am unable to pinpoint where. The log file shows no errors.
Clearly this is above my capability.
A lot more brighter people out there might be able to shed some light.

Windows 10, FPC 3.2.3, Laz 3.4
Ubuntu 24.04 LTS VM with all updates done (Did not test on main server)

CLI outputs for Win32 and Linux64
https://gist.github.com/rudiloos/6b684f … 57781b4b51

Thanks

Offline

#2 2024-11-11 05:42:11

zen010101
Member
Registered: 2024-06-15
Posts: 66

Re: TSynDaemon/TSynDaemonSettings memory leak

Please try this PR: https://github.com/synopse/mORMot2/pull/319


There are two reasons for this issue:

1. No call to TSampleDaemon.Free()
2. Even if called, an exception will occur because Free() will call Stop(), and this function has already been executed in the previous CommandLine() when the user presses the Enter key.

Solution:

1. In the Stop() method, check the Server status and skip execution if it is not running.
2. Call TSampleDaemon.Free() at the end of the program.

Offline

#3 2024-11-11 07:19:30

rudiloos
Member
From: South Africa
Registered: 2018-11-21
Posts: 6

Re: TSynDaemon/TSynDaemonSettings memory leak

Hi

I actually did put in a TSampleDaemon.Free() and got the exception as you said.

So then thought is was either of the two above (Sorry AB)

Like I said, there are brighter people out there.

Thank you very much.

Offline

#4 2024-11-11 17:38:26

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: TSynDaemon/TSynDaemonSettings memory leak

IIRC the Stop method should be reentrant.

Offline

#5 2024-11-12 05:02:00

zen010101
Member
Registered: 2024-06-15
Posts: 66

Re: TSynDaemon/TSynDaemonSettings memory leak

ab wrote:

IIRC the Stop method should be reentrant.

Yes, that's right, the comment of the stop() method says so:

    /// inherited class should override this abstract method with proper process
    // - should do nothing if the daemon was not running (e.g. already stopped)
    procedure Stop; virtual; abstract;

Offline

Board footer

Powered by FluxBB