From: S.Çağlar Onur Date: Fri, 15 Nov 2013 05:02:28 +0000 (-0500) Subject: free previously allocated memory if realloc fails in src/lxc/lsm/apparmor.c X-Git-Tag: lxc-1.0.0.beta1~137 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d380c7ff55799477fc39fe1bae2eaa0cdb57941e;p=thirdparty%2Flxc.git free previously allocated memory if realloc fails in src/lxc/lsm/apparmor.c Signed-off-by: S.Çağlar Onur Acked-by: Serge E. Hallyn --- diff --git a/src/lxc/lsm/apparmor.c b/src/lxc/lsm/apparmor.c index aaf80568d..f7f2ff966 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();