Commit 78bbb0a1 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

files-reg: Simplify have_seen_dead_pid

We've a special helper xrealloc_safe for reallocs.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 1ef50607
...@@ -554,28 +554,16 @@ static int have_seen_dead_pid(pid_t pid) ...@@ -554,28 +554,16 @@ static int have_seen_dead_pid(pid_t pid)
{ {
static pid_t *dead_pids = NULL; static pid_t *dead_pids = NULL;
static int n_dead_pids = 0; static int n_dead_pids = 0;
size_t i;
if (dead_pids) { for (i = 0; i < n_dead_pids; i++) {
int i;
void *m;
for (i = 0; i < n_dead_pids; i++)
if (dead_pids[i] == pid) if (dead_pids[i] == pid)
return 1; return 1;
}
m = realloc(dead_pids, sizeof(*dead_pids) * (n_dead_pids + 1)); if (xrealloc_safe(&dead_pids, sizeof(*dead_pids) * (n_dead_pids + 1)))
if (!m)
return -1; return -1;
dead_pids = m;
dead_pids[n_dead_pids++] = pid; dead_pids[n_dead_pids++] = pid;
} else {
dead_pids = malloc(sizeof(*dead_pids));
if (!dead_pids)
return -1;
*dead_pids = pid;
n_dead_pids++;
}
return 0; return 0;
} }
......
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