[CRIU] [PATCH 2/2] rst-malloc: use rst_mem_alloc_cont to allocate arrays

Andrey Vagin avagin at openvz.org
Tue Jan 26 11:58:13 PST 2016


From: Andrew Vagin <avagin at virtuozzo.com>

rst_mem_alloc() returns alligned slices. When we want to
allocate an array element, we don't expect to get a hole between
a new element and an old one.

Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
 cr-restore.c | 20 ++++++++++----------
 sk-tcp.c     |  2 +-
 timerfd.c    |  2 +-
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index 973f06e..3b0a38f 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -771,12 +771,12 @@ static int collect_child_pids(int state, int *n)
 
 	*n = 0;
 	list_for_each_entry(pi, &current->children, sibling) {
-		static pid_t *child;
+		pid_t *child;
 
 		if (pi->state != state)
 			continue;
 
-		child = rst_mem_alloc(sizeof(*child), RM_PRIVATE);
+		child = rst_mem_alloc_cont(sizeof(*child), RM_PRIVATE);
 		if (!child)
 			return -1;
 
@@ -2429,7 +2429,7 @@ static int prepare_posix_timers_from_fd(int pid)
 		if (ret <= 0)
 			break;
 
-		t = rst_mem_alloc(sizeof(struct restore_posix_timer), RM_PRIVATE);
+		t = rst_mem_alloc_cont(sizeof(struct restore_posix_timer), RM_PRIVATE);
 		if (!t)
 			break;
 
@@ -2461,7 +2461,7 @@ static int prepare_posix_timers(int pid, CoreEntry *core)
 
 	posix_timers_nr = tte->n_posix;
 	for (i = 0; i < posix_timers_nr; i++) {
-		t = rst_mem_alloc(sizeof(struct restore_posix_timer), RM_PRIVATE);
+		t = rst_mem_alloc_cont(sizeof(struct restore_posix_timer), RM_PRIVATE);
 		if (!t)
 			goto out;
 
@@ -2620,7 +2620,7 @@ static int prepare_rlimits_from_fd(int pid)
 		if (ret <= 0)
 			break;
 
-		r = rst_mem_alloc(sizeof(*r), RM_PRIVATE);
+		r = rst_mem_alloc_cont(sizeof(*r), RM_PRIVATE);
 		if (!r) {
 			pr_err("Can't allocate memory for resource %d\n",
 			       rlims_nr);
@@ -2657,7 +2657,7 @@ static int prepare_rlimits(int pid, CoreEntry *core)
 		return prepare_rlimits_from_fd(pid);
 
 	for (i = 0; i < rls->n_rlimits; i++) {
-		r = rst_mem_alloc(sizeof(*r), RM_PRIVATE);
+		r = rst_mem_alloc_cont(sizeof(*r), RM_PRIVATE);
 		if (!r) {
 			pr_err("Can't allocate memory for resource %d\n", i);
 			return -1;
@@ -2681,7 +2681,7 @@ static int signal_to_mem(SiginfoEntry *sie)
 	siginfo_t *info, *t;
 
 	info = (siginfo_t *) sie->siginfo.data;
-	t = rst_mem_alloc(sizeof(siginfo_t), RM_PRIVATE);
+	t = rst_mem_alloc_cont(sizeof(siginfo_t), RM_PRIVATE);
 	if (!t)
 		return -1;
 
@@ -2810,7 +2810,7 @@ rst_prep_creds_args(CredsEntry *ce, unsigned long *prev_pos)
 	}
 
 
-	args = rst_mem_alloc(sizeof(*args), RM_PRIVATE);
+	args = rst_mem_alloc_cont(sizeof(*args), RM_PRIVATE);
 	if (!args)
 		return ERR_PTR(-ENOMEM);
 
@@ -3016,7 +3016,7 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
 	list_for_each_entry(vma, &vmas->h, list) {
 		VmaEntry *vme;
 
-		vme = rst_mem_alloc(sizeof(*vme), RM_PRIVATE);
+		vme = rst_mem_alloc_cont(sizeof(*vme), RM_PRIVATE);
 		if (!vme)
 			goto err_nv;
 
@@ -3034,7 +3034,7 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
 	for (i = 0; i < mm->n_aios; i++) {
 		struct rst_aio_ring *raio;
 
-		raio = rst_mem_alloc(sizeof(*raio), RM_PRIVATE);
+		raio = rst_mem_alloc_cont(sizeof(*raio), RM_PRIVATE);
 		if (!raio)
 			goto err_nv;
 
diff --git a/sk-tcp.c b/sk-tcp.c
index b5e66b0..bce49f7 100644
--- a/sk-tcp.c
+++ b/sk-tcp.c
@@ -687,7 +687,7 @@ int rst_tcp_socks_prep(void)
 		if (ii->sk_fd == -1)
 			continue;
 
-		rs = rst_mem_alloc(sizeof(*rs), RM_PRIVATE);
+		rs = rst_mem_alloc_cont(sizeof(*rs), RM_PRIVATE);
 		if (!rs)
 			return -1;
 
diff --git a/timerfd.c b/timerfd.c
index 940190f..b91e047 100644
--- a/timerfd.c
+++ b/timerfd.c
@@ -119,7 +119,7 @@ int rst_timerfd_prep(void)
 	list_for_each_entry(ti, &rst_timerfds, rlist) {
 		TimerfdEntry *tfe = ti->tfe;
 
-		t = rst_mem_alloc(sizeof(*t), RM_PRIVATE);
+		t = rst_mem_alloc_cont(sizeof(*t), RM_PRIVATE);
 		if (!t)
 			return -1;
 
-- 
2.4.3



More information about the CRIU mailing list