From 0a5dc30456509f10fdc062f9caecc5d3d57b4306 Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Fri, 1 Feb 2013 15:23:12 -0500 Subject: [PATCH] policycoreutils: sandbox: seunshare: do not reassign realloc value We were doing x = realloc(x, ) which is a big no no, since it leaks X on allocation failure. Found with static analysis tool from David Malcolm. Signed-off-by: Eric Paris --- policycoreutils/sandbox/seunshare.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/policycoreutils/sandbox/seunshare.c b/policycoreutils/sandbox/seunshare.c index 3bb3c4b7..3fc5a8a5 100644 --- a/policycoreutils/sandbox/seunshare.c +++ b/policycoreutils/sandbox/seunshare.c @@ -774,10 +774,13 @@ killall (security_context_t execcon) continue; if (pids == max_pids) { - if (!(pid_table = realloc(pid_table, 2*pids*sizeof(pid_t)))) { + pid_t *new_pid_table = realloc(pid_table, 2*pids*sizeof(pid_t)); + if (!new_pid_table) { + free(pid_table); (void)closedir(dir); return -1; } + pid_table = new_pid_table; max_pids *= 2; } pid_table[pids++] = pid;