[lxc-devel] [PATCH] Free allocated memory on failure (v2)

Serge Hallyn serge.hallyn at ubuntu.com
Mon Sep 28 14:30:13 UTC 2015


Quoting Christian Brauner (christianvanbrauner at gmail.com):
> Signed-off-by: Christian Brauner <christianvanbrauner at gmail.com>

Thanks!

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

> ---
>  src/lxc/bdev.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/src/lxc/bdev.c b/src/lxc/bdev.c
> index 21a64f7..846fd82 100644
> --- a/src/lxc/bdev.c
> +++ b/src/lxc/bdev.c
> @@ -2461,12 +2461,15 @@ static int overlayfs_clonepaths(struct bdev *orig, struct bdev *new, const char
>  		// and needs to be on the same filesystem as upperdir,
>  		// so it's OK for it to be empty.
>  		work = malloc(lastslashidx + 7);
> -		if (!work)
> +		if (!work) {
> +			free(delta);
>  			return -1;
> +		}
>  		strncpy(work, new->dest, lastslashidx+1);
>  		strcpy(work+lastslashidx, "olwork");
>  		if (mkdir(work, 0755) < 0) {
>  			SYSERROR("error: mkdir %s", work);
> +			free(delta);
>  			free(work);
>  			return -1;
>  		}
> -- 
> 2.5.3
> 
> _______________________________________________
> 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