Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource leak when subprocess_create_ex() fails #85

Open
wn2000 opened this issue Apr 25, 2024 · 3 comments
Open

Resource leak when subprocess_create_ex() fails #85

wn2000 opened this issue Apr 25, 2024 · 3 comments

Comments

@wn2000
Copy link

wn2000 commented Apr 25, 2024

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

Example:

subprocess.h/subprocess.h

Lines 876 to 880 in 7e59b69

if (0 != posix_spawnp(&child, commandLine[0], &actions, SUBPROCESS_NULL,
(char *const *)commandLine, used_environment)) {
posix_spawn_file_actions_destroy(&actions);
return -1;
}

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

@starseeker
Copy link

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
Copy link

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

@sheredom
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants