From d48d6c7267f72334a51c7dede32443b120f02f8c Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Tue, 15 Apr 2014 21:59:21 +0400 Subject: [PATCH] posix-timers: Helper for freeing proc parsed data Signed-off-by: Pavel Emelyanov --- 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 f5d089c53..568bf4a27 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 82501845f..8a758dd03 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 b90a79dc4..2bdcf6bfa 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: