When watching file descriptors, duplicate the default_bar_style string rather than copying its pointer, to avoid double-free() (#163).

This commit is contained in:
Andrew Wood
2025-07-25 23:40:41 +01:00
parent cd7c8f7849
commit 092a30dd7d
+11
View File
@@ -490,6 +490,7 @@ int pv_watchpid_scanfds(pvstate_t state,
info_array[use_idx].state->control.name = NULL;
info_array[use_idx].state->control.format_string = NULL;
info_array[use_idx].state->control.output_name = NULL;
info_array[use_idx].state->control.default_bar_style = NULL;
/*@+mustfreeonly@ */
info_array[use_idx].state->control.default_format[0] = '\0';
use_format_string =
@@ -498,6 +499,16 @@ int pv_watchpid_scanfds(pvstate_t state,
(void) pv_snprintf(info_array[use_idx].state->control.default_format, PV_SIZEOF_DEFAULT_FORMAT,
"%.510s", use_format_string);
/*
* Duplicate the default bar style string, if there is one.
*/
if (NULL != state->control.default_bar_style) {
/*@-mustfreeonly@ *//* splint - this is not a leak, this is a new entry. */
info_array[use_idx].state->control.default_bar_style =
pv_strdup(state->control.default_bar_style);
/*@+mustfreeonly@ */
}
/*
* Copy over all the display values, blanking out the
* dynamically allocated parts as above; then set the