Blame SOURCES/0004-key-file-ply_key_file_get_value-returns-duplicated-m.patch

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