[lxc-devel] [PATCH] Fix invalid free() in lxc_global_config_value().

Andrey Mazo mazo at telum.ru
Mon Dec 23 17:17:10 UTC 2013


Commit 4878dac496543dae0a26f5c1156bbfda63c8ea62 introduced possible
incorrect usage of free().
Also remove unneeded strdup().

Signed-off-by: Andrey Mazo <mazo at telum.ru>
---
 src/lxc/utils.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/src/lxc/utils.c b/src/lxc/utils.c
index 832dbe5..2c0e07e 100644
--- a/src/lxc/utils.c
+++ b/src/lxc/utils.c
@@ -256,13 +256,10 @@ const char *lxc_global_config_value(const char *option_name)
 
 	char *user_config_path = NULL;
 	char *user_lxc_path = NULL;
-	char *user_home = NULL;
 
 	if (geteuid() > 0) {
-		user_home = getenv("HOME");
-		if (user_home)
-			user_home = strdup(user_home);
-		else
+		const char *user_home = getenv("HOME");
+		if (!user_home)
 			user_home = "/";
 
 		user_config_path = malloc(sizeof(char) * (22 + strlen(user_home)));
@@ -270,8 +267,6 @@ const char *lxc_global_config_value(const char *option_name)
 
 		sprintf(user_config_path, "%s/.config/lxc/lxc.conf", user_home);
 		sprintf(user_lxc_path, "%s/.local/share/lxc/", user_home);
-
-		free(user_home);
 	}
 	else {
 		user_config_path = strdup(LXC_GLOBAL_CONF);
-- 
1.8.4.5



More information about the lxc-devel mailing list