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)
{
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();
......
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