From 13700e1fb8bfc2c6aae687ad0bfb5b943bafcaa2 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Mon, 2 Jun 2025 23:23:05 +0200 Subject: [PATCH] windows: close child process handle only once Calling CloseHandle multiple times for the same handle can lead to exceptions while debugging according to documentation. Mimic the waitpid handling for success cases to behave more like the Unix version which would "reap the zombie". Doing this for an unsuccessful call is off, but the loop is never entered again, so I guess it's okay and worth it to reduce the amount of Windows specific definitions in source files. Signed-off-by: Tobias Stoeckmann --- libarchive/archive_read_support_filter_program.c | 3 --- libarchive/archive_windows.c | 1 + libarchive/archive_write_add_filter_program.c | 3 --- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/libarchive/archive_read_support_filter_program.c b/libarchive/archive_read_support_filter_program.c index 9e825223b..55c617c9c 100644 --- a/libarchive/archive_read_support_filter_program.c +++ b/libarchive/archive_read_support_filter_program.c @@ -242,9 +242,6 @@ child_stop(struct archive_read_filter *self, struct program_filter *state) state->waitpid_return = waitpid(state->child, &state->exit_status, 0); } while (state->waitpid_return == -1 && errno == EINTR); -#if defined(_WIN32) && !defined(__CYGWIN__) - CloseHandle(state->child); -#endif state->child = 0; } diff --git a/libarchive/archive_windows.c b/libarchive/archive_windows.c index 349114a61..0ccea0f81 100644 --- a/libarchive/archive_windows.c +++ b/libarchive/archive_windows.c @@ -648,6 +648,7 @@ __la_waitpid(HANDLE child, int *status, int option) } } while (cs == STILL_ACTIVE); + CloseHandle(child); *status = (int)(cs & 0xff); return (0); } diff --git a/libarchive/archive_write_add_filter_program.c b/libarchive/archive_write_add_filter_program.c index c661cc7f4..66ace04cf 100644 --- a/libarchive/archive_write_add_filter_program.c +++ b/libarchive/archive_write_add_filter_program.c @@ -375,9 +375,6 @@ cleanup: close(data->child_stdout); while (waitpid(data->child, &status, 0) == -1 && errno == EINTR) continue; -#if defined(_WIN32) && !defined(__CYGWIN__) - CloseHandle(data->child); -#endif data->child = 0; if (status != 0) { -- 2.47.2