From ca7997fe7dc67074b7b5108aaf2275a02e8630bc Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Wed, 12 Nov 2025 14:31:22 +0000 Subject: [PATCH] Use the new watchfd_count to size the array, not the one we just zeroed, otherwise multiple --watchfd arguments result in a memory error (#170) --- src/pv/state.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pv/state.c b/src/pv/state.c index ba30016..018be51 100644 --- a/src/pv/state.c +++ b/src/pv/state.c @@ -836,14 +836,14 @@ void pv_state_watchfds(pvstate_t state, unsigned int watchfd_count, const pid_t state->watchfd.multiple_pids = false; /* Allocate an empty new array of the right size. */ - new_array = malloc((1 + state->watchfd.count) * sizeof(*new_array)); + new_array = malloc((1 + watchfd_count) * sizeof(*new_array)); if (NULL == new_array) { /*@-mustfreefresh@ *//* see similar _() issue above */ pv_error("%s: %s", _("buffer allocation failed"), strerror(errno)); /*@+mustfreefresh@ */ return; } - memset(new_array, 0, (1 + state->watchfd.count) * sizeof(*new_array)); + memset(new_array, 0, (1 + watchfd_count) * sizeof(*new_array)); state->watchfd.watching = new_array; /* Populate the new array with the values supplied. */