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)

This commit is contained in:
Andrew Wood
2025-11-12 14:31:22 +00:00
parent 22b729f9ea
commit ca7997fe7d
+2 -2
View File
@@ -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. */