Handle leak in sb-ext:run-program on Windows

Bug #1724472 reported by Eitaro Fukamachi on 2017-10-18
This bug affects 1 person
Affects Status Importance Assigned to Milestone

Bug Description

Calling sb-ext:run-program creates a new handle and keeps it even after the process exited on Windows.

## Reproducible Flow

1. Create a file run-wmic.lisp

;; run-wmic.lisp
 (sb-ext:run-program "C:\\Windows\\System32\\Wbem\\WMIC.exe"
                     '("Path" "Win32_Battery" "Get" "EstimatedChargeRemaining"))
 (princ ".") (force-output)
 (sleep 1))

2. Load it with SBCL
$ sbcl --load run-wmic.lisp

3. Check the number of handles with Task Manager

## Environment

SBCL 1.3.15
Windows 10 Home

On Wed 18 Oct 2017 at 07:38, Eitaro Fukamachi <email address hidden> wrote:
> Calling sb-ext:run-program creates a new handle and keeps it even after
> the process exited on Windows.

Can confirm.

We found this in
id:<email address hidden>
but I mistakenly thought it was a FD_SETSIZE problem.

After realising, that it was a leak, this workaround worked for our
specific use-case:

;; :error *error-output* leaks file descriptors on windows
:error #+(or mswindows windows) :output
       #-(or mswindows windows) *error-output*

Stas Boukarev (stassats) wrote :

Fixed in 71a2e512b637463c5d486ce421aacaa7b74c56ee.
Though, it's not automatically closed, but as long as you call PROCESS-EXIT-CODE or PROCESS-EXIT-STATUS after the process has finished it'll be closed.
There's also PROCESS-CLOSE which was supposed to close the handle, but it was crashing on windows, I fixed that as well and it can be used to close the handle at any time.

And whenever PROCESS-EXIT-CODE/STATUS are called on any finished process all other finished processes' handles will be also closed.

Changed in sbcl:
status: New → Fix Committed
Eitaro Fukamachi (fukamachi) wrote :

I appreciate the quick response and fix!

Changed in sbcl:
status: Fix Committed → Fix Released
Eitaro Fukamachi (fukamachi) wrote :

I confirmed the exited process handle are released after calling sb-ext:process-status with SBCL 1.4.1.

Well, now I have a suggestion about the behaviour.
The result process object from "sb-ext:run-program :wait t" would always be exited, however, the process handle won't be closed until getting its status.
I think it's cool if the handles will be closed automatically.

Stas Boukarev (stassats) wrote :

Done as a part of ce7eec29a758686a773273676fa390f4a8a1ecd2

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers