subprocess.h icon indicating copy to clipboard operation
subprocess.h copied to clipboard

Resource leak when `subprocess_create_ex()` fails

Open wn2000 opened this issue 1 year ago • 3 comments

The subprocess_create_ex() function just has return -1 in case of an error, without properly closing already open file descriptors.

Example: https://github.com/sheredom/subprocess.h/blob/7e59b6924aa0e1a595be86fdeb1d4c28835aa0b9/subprocess.h#L876-L880

In my test, trying to call this function with a non-existing command results in 6 more new FDs each time.

wn2000 avatar Apr 25 '24 06:04 wn2000

The following is helpful (at least on Linux) for debugging this (see https://developers.redhat.com/articles/2023/01/09/how-use-valgrind-track-file-descriptors#valgrind___track_fds_yes):

valgrind -q --tool=none --track-fds=yes

starseeker avatar May 20 '24 16:05 starseeker

(Note - found out the hard way if you forget to call subprocess_destroy, fd leaks - even in normal usage - are one of the symptoms)

starseeker avatar May 20 '24 17:05 starseeker

Thanks for the report. Super busy at the moment but when I get the time I'll take a look!

sheredom avatar May 21 '24 15:05 sheredom