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

Serge Hallyn serge.hallyn at ubuntu.com
Mon Dec 23 18:31:46 UTC 2013


Quoting Andrey Mazo (mazo at telum.ru):
> Commit 4878dac496543dae0a26f5c1156bbfda63c8ea62 introduced possible
> incorrect usage of free().
> Also remove unneeded strdup().
> 
> Signed-off-by: Andrey Mazo <mazo at telum.ru>

Thanks, I had added an strdup instead, but that's not needed.
Will push yours.

Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

> ---
>  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
> 
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel


More information about the lxc-devel mailing list