From 322a3635fa8eed7c3ee4c849518e3b002cbf089a Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Mon, 15 Oct 2018 21:13:58 -0400
Subject: [PATCH 051/142] 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 47157bc..d0d9ce3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -296,8 +296,8 @@ load_settings (state_t    *state,
 {
         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);
@@ -323,24 +323,27 @@ load_settings (state_t    *state,
         }
 
         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);
                 }
         }
 
@@ -348,10 +351,12 @@ load_settings (state_t    *state,
 
         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;
diff --git a/src/plugins/splash/two-step/plugin.c b/src/plugins/splash/two-step/plugin.c
index 7ae9910..7307e19 100644
--- a/src/plugins/splash/two-step/plugin.c
+++ b/src/plugins/splash/two-step/plugin.c
@@ -662,6 +662,8 @@ create_plugin (ply_key_file_t *key_file)
                         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 ();
-- 
2.7.4

