[lxc-devel] [PATCH] free previously allocated memory if realloc fails in src/lxc/lsm/apparmor.c

Serge Hallyn serge.hallyn at ubuntu.com
Mon Nov 18 15:35:11 UTC 2013


Quoting S.Çağlar Onur (caglar at 10ur.org):
> Signed-off-by: S.Çağlar Onur <caglar at 10ur.org>

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

> ---
>  src/lxc/lsm/apparmor.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/src/lxc/lsm/apparmor.c b/src/lxc/lsm/apparmor.c
> index aaf8056..f7f2ff9 100644
> --- a/src/lxc/lsm/apparmor.c
> +++ b/src/lxc/lsm/apparmor.c
> @@ -68,7 +68,7 @@ static char *apparmor_process_label_get(pid_t pid)
>  {
>  	char path[100], *space;
>  	int ret;
> -	char *buf = NULL;
> +	char *buf = NULL, *newbuf;
>  	int sz = 0;
>  	FILE *f;
>  
> @@ -88,14 +88,16 @@ again:
>  		return NULL;
>  	}
>  	sz += 1024;
> -	buf = realloc(buf, sz);
> -	if (!buf) {
> +	newbuf = realloc(buf, sz);
> +	if (!newbuf) {
> +		free(buf);
>  		ERROR("out of memory");
>  		process_lock();
>  		fclose(f);
>  		process_unlock();
>  		return NULL;
>  	}
> +	buf = newbuf;
>  	memset(buf, 0, sz);
>  	ret = fread(buf, 1, sz - 1, f);
>  	process_lock();
> -- 
> 1.8.3.2
> 
> 
> ------------------------------------------------------------------------------
> DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
> OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
> Free app hosting. Or install the open source package on any LAMP server.
> Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
> http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
> _______________________________________________
> Lxc-devel mailing list
> Lxc-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/lxc-devel




More information about the lxc-devel mailing list