Blob Blame History Raw
From 7daf5993995baad0f5c7f7ae3822dae37eb9f46f Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose@redhat.com>
Date: Fri, 30 Oct 2020 16:44:23 +0100
Subject: [PATCH 4/6] service: do not copy option values to avoid memory leaks

---
 service/realm-adcli-enroll.c | 15 ++++++++-------
 service/realm-options.c      |  8 +++-----
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/service/realm-adcli-enroll.c b/service/realm-adcli-enroll.c
index 2731283..e0d752b 100644
--- a/service/realm-adcli-enroll.c
+++ b/service/realm-adcli-enroll.c
@@ -80,7 +80,8 @@ realm_adcli_enroll_join_async (RealmDisco *disco,
 	GBytes *input = NULL;
 	const gchar *upn;
 	GPtrArray *args;
-	const gchar *os;
+	const gchar *os_n = NULL;
+	const gchar *os_v = NULL;
 	gchar *ccache_arg = NULL;
 	gchar *upn_arg = NULL;
 	gchar *server_arg = NULL;
@@ -144,16 +145,16 @@ realm_adcli_enroll_join_async (RealmDisco *disco,
 			g_ptr_array_add (args, (gpointer)computer_ou);
 	}
 
-	os = realm_options_ad_specific (options, "os-name");
-	if (os != NULL && !g_str_equal (os, "")) {
+	os_n = realm_options_ad_specific (options, "os-name");
+	if (os_n != NULL && !g_str_equal (os_n, "")) {
 		g_ptr_array_add (args, "--os-name");
-		g_ptr_array_add (args, (gpointer)os);
+		g_ptr_array_add (args, (gpointer)os_n);
 	}
 
-	os = realm_options_ad_specific (options, "os-version");
-	if (os != NULL && !g_str_equal (os, "")) {
+	os_v = realm_options_ad_specific (options, "os-version");
+	if (os_v != NULL && !g_str_equal (os_v, "")) {
 		g_ptr_array_add (args, "--os-version");
-		g_ptr_array_add (args, (gpointer)os);
+		g_ptr_array_add (args, (gpointer)os_v);
 	}
 
 	switch (cred->type) {
diff --git a/service/realm-options.c b/service/realm-options.c
index d42eb7c..4ebd6c0 100644
--- a/service/realm-options.c
+++ b/service/realm-options.c
@@ -179,7 +179,7 @@ realm_options_computer_name (GVariant *options,
 		g_free (section);
 	}
 
-	return g_strdup (computer_name);
+	return computer_name;
 }
 
 const gchar *
@@ -197,22 +197,20 @@ realm_options_ad_specific (GVariant *options,
 		value = realm_settings_value ("active-directory", option_name);
 	}
 
-	return g_strdup (value);
+	return value;
 }
 
 gboolean realm_option_use_ldaps (GVariant *options)
 {
-	gchar *use_ldaps_str;
+	const gchar *use_ldaps_str;
 
 	use_ldaps_str = realm_options_ad_specific (options,
 	                                          REALM_DBUS_OPTION_USE_LDAPS);
 	if (use_ldaps_str != NULL
 	            && ( g_ascii_strcasecmp (use_ldaps_str, "True") == 0
 	                || g_ascii_strcasecmp (use_ldaps_str, "Yes") == 0)) {
-		g_free (use_ldaps_str);
 		return TRUE;
 	}
-	g_free (use_ldaps_str);
 
 	return FALSE;
 }
-- 
2.26.2