[CRIU] [PATCH 4/8] posix-timers: Helper for freeing proc parsed data

Pavel Emelyanov xemul at parallels.com
Tue Apr 15 10:59:21 PDT 2014


Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 include/posix-timer.h |  1 +
 parasite-syscall.c    |  7 +------
 proc_parse.c          | 16 +++++++++++-----
 3 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/include/posix-timer.h b/include/posix-timer.h
index f5d089c..568bf4a 100644
--- a/include/posix-timer.h
+++ b/include/posix-timer.h
@@ -22,5 +22,6 @@ struct proc_posix_timers_stat {
 };
 
 extern int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat * args);
+void free_posix_timers(struct proc_posix_timers_stat *st);
 
 #endif /* __CR_PROC_POSIX_TIMER_H__ */
diff --git a/parasite-syscall.c b/parasite-syscall.c
index 8250184..8a758dd 100644
--- a/parasite-syscall.c
+++ b/parasite-syscall.c
@@ -702,12 +702,7 @@ int parasite_dump_posix_timers_seized(struct proc_posix_timers_stat *proc_args,
 	}
 
 end_posix:
-	while (!list_empty(&proc_args->timers)) {
-		temp = list_first_entry(&proc_args->timers, struct proc_posix_timer, list);
-		list_del(&temp->list);
-		xfree(temp);
-	}
-
+	free_posix_timers(proc_args);
 	return ret;
 }
 
diff --git a/proc_parse.c b/proc_parse.c
index b90a79d..2bdcf6b 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -1337,6 +1337,16 @@ err:
 	return ret;
 }
 
+void free_posix_timers(struct proc_posix_timers_stat *st)
+{
+	while (!list_empty(&st->timers)) {
+		struct proc_posix_timer *timer;
+		timer = list_first_entry(&st->timers, struct proc_posix_timer, list);
+		list_del(&timer->list);
+		xfree(timer);
+	}
+}
+
 int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat *args)
 {
 	int ret = 0;
@@ -1409,11 +1419,7 @@ int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat *args)
 		args->timer_n++;
 	}
 err:
-	while (!list_empty(&args->timers)) {
-		timer = list_first_entry(&args->timers, struct proc_posix_timer, list);
-		list_del(&timer->list);
-		xfree(timer);
-	}
+	free_posix_timers(args);
 	pr_perror("Parse error in posix timers proc file!");
 	ret = -1;
 out:
-- 
1.8.4.2


More information about the CRIU mailing list