Commit b3c6742a authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

restore: Use xmalloc instead of plain malloc

And add error checking
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
parent 2e31cb1f
...@@ -430,17 +430,22 @@ static unsigned long find_shmem_id(unsigned long addr) ...@@ -430,17 +430,22 @@ static unsigned long find_shmem_id(unsigned long addr)
return 0; return 0;
} }
static void save_shmem_id(struct shmem_entry *e) static int save_shmem_id(struct shmem_entry *e)
{ {
struct shmem_id *si; struct shmem_id *si;
si = malloc(sizeof(*si)); si = xmalloc(sizeof(*si));
if (!si)
return -1;
si->addr = e->start; si->addr = e->start;
si->end = e->end; si->end = e->end;
si->shmid = e->shmid; si->shmid = e->shmid;
si->next = shmem_ids; si->next = shmem_ids;
shmem_ids = si; shmem_ids = si;
return 0;
} }
static int prepare_shmem(int pid) static int prepare_shmem(int pid)
...@@ -463,7 +468,8 @@ static int prepare_shmem(int pid) ...@@ -463,7 +468,8 @@ static int prepare_shmem(int pid)
return -1; return -1;
} }
save_shmem_id(&e); if (save_shmem_id(&e))
return -1;
} }
close(sh_fd); close(sh_fd);
...@@ -988,9 +994,8 @@ static int prepare_pipes(int pid) ...@@ -988,9 +994,8 @@ static int prepare_pipes(int pid)
if (pipes_fd < 0) if (pipes_fd < 0)
return -1; return -1;
buf = malloc(buf_size); buf = xmalloc(buf_size);
if (!buf) { if (!buf) {
pr_perror("Can't allocate memory\n");
close(pipes_fd); close(pipes_fd);
return -1; return -1;
} }
...@@ -1159,7 +1164,10 @@ static int restore_task_with_children(int my_pid) ...@@ -1159,7 +1164,10 @@ static int restore_task_with_children(int my_pid)
if (e.nr_children > 0) { if (e.nr_children > 0) {
i = e.nr_children * sizeof(int); i = e.nr_children * sizeof(int);
pids = malloc(i); pids = xmalloc(i);
if (!pids)
exit(1);
ret = read(fd, pids, i); ret = read(fd, pids, i);
if (ret != i) { if (ret != i) {
pr_perror("%d: Can't read children pids\n", my_pid); pr_perror("%d: Can't read children pids\n", my_pid);
......
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