From 862bdf3d26ac8fd61c7f7f6664bf0999774be434 Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Wed, 25 Aug 2010 14:31:56 +0200 Subject: libps (_proc_stat_free): Fix memory leak The thread_waits field was never freed; this change adds the code to do so if the corresponding flag is set. Users are also warned of the consequences, namely, that they should not free process proc_stats before all their associated thread ones are gone, since the latter may reference the former's thread_waits field. However, with the normal interface (ie. ps_context_free), all proc_stats are freed at once, so this is not an issue. * libps/procstat.c (_proc_stat_free): Free ps->thread_waits if PSTAT_THREAD_WAITS flag is set. * libps/ps.h (_proc_stat_free): Document that thread proc_stats must be freed before process proc_stat can be. --- libps/procstat.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libps/procstat.c') diff --git a/libps/procstat.c b/libps/procstat.c index 33a01cc1..0717065c 100644 --- a/libps/procstat.c +++ b/libps/procstat.c @@ -1058,6 +1058,8 @@ _proc_stat_free (ps) MFREEMEM (PSTAT_ENV, env, ps->env_len, ps->env_vm_alloced, 0, char); MFREEMEM (PSTAT_TASK_EVENTS, task_events_info, ps->task_events_info_size, 0, &ps->task_events_info_buf, char); + MFREEMEM (PSTAT_THREAD_WAITS, thread_waits, ps->thread_waits_len, + ps->thread_waits_vm_alloced, 0, char); FREE (ps); } -- cgit v1.2.3