From 092a30dd7dbb720ccf29939da9f3980e545ae4b9 Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Fri, 25 Jul 2025 23:40:41 +0100 Subject: [PATCH] When watching file descriptors, duplicate the default_bar_style string rather than copying its pointer, to avoid double-free() (#163). --- src/pv/watchpid.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/pv/watchpid.c b/src/pv/watchpid.c index b5aa8ba..17270f0 100644 --- a/src/pv/watchpid.c +++ b/src/pv/watchpid.c @@ -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