]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
free previously allocated memory if realloc fails in src/lxc/lsm/apparmor.c
authorS.Çağlar Onur <caglar@10ur.org>
Fri, 15 Nov 2013 05:02:28 +0000 (00:02 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Mon, 18 Nov 2013 15:47:45 +0000 (10:47 -0500)
Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lsm/apparmor.c

index aaf80568df3b1142d377f28da979ba721ef1b395..f7f2ff966995949c1b250587078d253e3fe87cb4 100644 (file)
@@ -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();