]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
windows: close child process handle only once
authorTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 2 Jun 2025 21:23:05 +0000 (23:23 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 2 Jun 2025 21:23:05 +0000 (23:23 +0200)
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 <tobias@stoeckmann.org>
libarchive/archive_read_support_filter_program.c
libarchive/archive_windows.c
libarchive/archive_write_add_filter_program.c

index 9e825223b26c0fa3191613b785240514e326f92d..55c617c9cb5a432195171e92e88daba2c7bb9de1 100644 (file)
@@ -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;
        }
 
index 349114a61ff3c2513e04124e605a5fa60dd35e07..0ccea0f818b90cd4edd185901131fc74223cad23 100644 (file)
@@ -648,6 +648,7 @@ __la_waitpid(HANDLE child, int *status, int option)
                }
        } while (cs == STILL_ACTIVE);
 
+       CloseHandle(child);
        *status = (int)(cs & 0xff);
        return (0);
 }
index c661cc7f412fc7d42c4842bde413dc80399c8335..66ace04cfb15a7bb53332fbe7a7e5f8945156ed8 100644 (file)
@@ -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) {