Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-10

Reusing a TProcess object (issue 19997)

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Vincent Snijders

Hi,

Is it allowed to execute a TProcess object more than once? And if yes, different command lines be used?

The reason I ask is issue 19997, each invocation of the compiler in Lazarus leaks a process handle and a thread handle on windows. (not tested on other OS-es).

If is it allowed to re-use TProcess object, how can it be done without leaking handles?

Vincent

Sven Barth
to Vincent Snijders
Vincent Snijders wrote 11 lines
Hi, Is it allowed to execute a TProcess object more than once? And if yes, different command lines be used? The reason I ask is issue 19997, each invocation of the compiler in Lazarus leaks a process handle and a thread handle on windows. (not tested on other OS-es). If is it allowed to re-use TProcess object, how can it be done without leaking handles?

A quick look at the implementation of TProcess let's me come to the conclusion that it's not allowed to reuse TProcess. If you look at TProcess.Destroy you'll see that only there "FreeStreams" and "CloseProcessHandles" is called. So if you create a new process new streams and new handles (on Windows) are created (so you are not only leaking handles, but also streams if you use "poUsePipes").

You might be able to workaround this by introducing a descendant of TProcess and adding a method "Reset" which calls "CloseProcessHandles" and frees the streams (you can't use "FreeStreams", because it's private, but the streams are protected).

Regards,
Sven