Commit d380c7ff by S.Çağlar Onur Committed by Stéphane Graber

free previously allocated memory if realloc fails in src/lxc/lsm/apparmor.c

parent 6127da6b
...@@ -68,7 +68,7 @@ static char *apparmor_process_label_get(pid_t pid) ...@@ -68,7 +68,7 @@ static char *apparmor_process_label_get(pid_t pid)
{ {
char path[100], *space; char path[100], *space;
int ret; int ret;
char *buf = NULL; char *buf = NULL, *newbuf;
int sz = 0; int sz = 0;
FILE *f; FILE *f;
...@@ -88,14 +88,16 @@ again: ...@@ -88,14 +88,16 @@ again:
return NULL; return NULL;
} }
sz += 1024; sz += 1024;
buf = realloc(buf, sz); newbuf = realloc(buf, sz);
if (!buf) { if (!newbuf) {
free(buf);
ERROR("out of memory"); ERROR("out of memory");
process_lock(); process_lock();
fclose(f); fclose(f);
process_unlock(); process_unlock();
return NULL; return NULL;
} }
buf = newbuf;
memset(buf, 0, sz); memset(buf, 0, sz);
ret = fread(buf, 1, sz - 1, f); ret = fread(buf, 1, sz - 1, f);
process_lock(); process_lock();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment