From b8d406161ee95ad4fa1a478d262993090404608f Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Mon, 15 Oct 2018 21:13:58 -0400 Subject: [PATCH 4/6] key-file: ply_key_file_get_value returns duplicated memory, don't leak For some reason I made the same api misdesign with ply_key_file_t that I made when writing GKeyFile...it returns duplicated memory for no good reason. This commit sprinkles frees around. --- src/main.c | 13 +++++++++---- src/plugins/splash/two-step/plugin.c | 2 ++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main.c b/src/main.c index 841fe6b..e44de7b 100644 --- a/src/main.c +++ b/src/main.c @@ -268,116 +268,121 @@ on_system_update (state_t *state, } static void show_messages (state_t *state) { if (state->boot_splash == NULL) { ply_trace ("not displaying messages, since no boot splash"); return; } ply_list_node_t *node = ply_list_get_first_node (state->messages); while (node != NULL) { ply_list_node_t *next_node; char *message = ply_list_node_get_data (node); ply_trace ("displaying messages"); ply_boot_splash_display_message (state->boot_splash, message); next_node = ply_list_get_next_node (state->messages, node); node = next_node; } } static bool load_settings (state_t *state, const char *path, char **theme_path) { ply_key_file_t *key_file = NULL; bool settings_loaded = false; - const char *scale_string; - const char *splash_string; + char *scale_string = NULL; + char *splash_string = NULL; ply_trace ("Trying to load %s", path); key_file = ply_key_file_new (path); if (!ply_key_file_load (key_file)) goto out; splash_string = ply_key_file_get_value (key_file, "Daemon", "Theme"); if (splash_string == NULL) goto out; asprintf (theme_path, PLYMOUTH_RUNTIME_THEME_PATH "%s/%s.plymouth", splash_string, splash_string); ply_trace ("Checking if %s exists", *theme_path); if (!ply_file_exists (*theme_path)) { ply_trace ("%s not found, fallbacking to " PLYMOUTH_THEME_PATH, *theme_path); asprintf (theme_path, PLYMOUTH_THEME_PATH "%s/%s.plymouth", splash_string, splash_string); } if (isnan (state->splash_delay)) { - const char *delay_string; + char *delay_string; delay_string = ply_key_file_get_value (key_file, "Daemon", "ShowDelay"); if (delay_string != NULL) { state->splash_delay = atof (delay_string); ply_trace ("Splash delay is set to %lf", state->splash_delay); + free (delay_string); } } if (isnan (state->device_timeout)) { - const char *timeout_string; + char *timeout_string; timeout_string = ply_key_file_get_value (key_file, "Daemon", "DeviceTimeout"); if (timeout_string != NULL) { state->device_timeout = atof (timeout_string); ply_trace ("Device timeout is set to %lf", state->device_timeout); + + free (timeout_string); } } scale_string = ply_key_file_get_value (key_file, "Daemon", "DeviceScale"); if (scale_string != NULL) { ply_set_device_scale (strtoul (scale_string, NULL, 0)); + free (scale_string); } settings_loaded = true; out: + free (splash_string); ply_key_file_free (key_file); return settings_loaded; } static void show_detailed_splash (state_t *state) { ply_boot_splash_t *splash; if (state->boot_splash != NULL) return; ply_trace ("Showing detailed splash screen"); splash = show_theme (state, NULL); if (splash == NULL) { ply_trace ("Could not start detailed splash screen, this could be a problem."); return; } state->boot_splash = splash; show_messages (state); update_display (state); } static const char * command_line_get_string_after_prefix (const char *command_line, const char *prefix) diff --git a/src/plugins/splash/two-step/plugin.c b/src/plugins/splash/two-step/plugin.c index 070741d..52986d2 100644 --- a/src/plugins/splash/two-step/plugin.c +++ b/src/plugins/splash/two-step/plugin.c @@ -631,60 +631,62 @@ create_plugin (ply_key_file_t *key_file) if (color != NULL) plugin->background_start_color = strtol (color, NULL, 0); else plugin->background_start_color = PLYMOUTH_BACKGROUND_START_COLOR; free (color); color = ply_key_file_get_value (key_file, "two-step", "BackgroundEndColor"); if (color != NULL) plugin->background_end_color = strtol (color, NULL, 0); else plugin->background_end_color = PLYMOUTH_BACKGROUND_END_COLOR; free (color); progress_function = ply_key_file_get_value (key_file, "two-step", "ProgressFunction"); if (progress_function != NULL) { if (strcmp (progress_function, "wwoods") == 0) { ply_trace ("Using wwoods progress function"); plugin->progress_function = PROGRESS_FUNCTION_TYPE_WWOODS; } else if (strcmp (progress_function, "linear") == 0) { ply_trace ("Using linear progress function"); plugin->progress_function = PROGRESS_FUNCTION_TYPE_LINEAR; } else { ply_trace ("unknown progress function %s, defaulting to linear", progress_function); plugin->progress_function = PROGRESS_FUNCTION_TYPE_LINEAR; } + + free (progress_function); } plugin->views = ply_list_new (); return plugin; } static void free_views (ply_boot_splash_plugin_t *plugin) { ply_list_node_t *node; ply_trace ("freeing views"); node = ply_list_get_first_node (plugin->views); while (node != NULL) { ply_list_node_t *next_node; view_t *view; view = ply_list_node_get_data (node); next_node = ply_list_get_next_node (plugin->views, node); view_free (view); ply_list_remove_node (plugin->views, node); node = next_node; } ply_list_free (plugin->views); -- 2.17.1