[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/4] libps (_proc_stat_free): Fix memory leak

From: Jeremie Koenig
Subject: [PATCH 2/4] libps (_proc_stat_free): Fix memory leak
Date: Wed, 25 Aug 2010 14:31:56 +0200

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 |    2 ++
 libps/ps.h       |    4 +++-
 2 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/libps/procstat.c b/libps/procstat.c
index 33a01cc..0717065 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);
diff --git a/libps/ps.h b/libps/ps.h
index f8bd13f..26ecb9e 100644
--- a/libps/ps.h
+++ b/libps/ps.h
@@ -454,7 +454,9 @@ error_t _proc_stat_create (pid_t pid, struct ps_context 
 /* Frees PS and any memory/ports it references.  Users shouldn't use this
    routine; proc_stats are normally freed only when their ps_context goes
-   away.  */
+   away.  Insubordinate users will make sure they free the thread proc_stats
+   before they free the corresponding process proc_stat since the thread_wait
+   fields of the former may reference the latter.  */
 void _proc_stat_free (struct proc_stat *ps);
 /* Adds FLAGS to PS's flags, fetching information as necessary to validate

reply via email to

[Prev in Thread] Current Thread [Next in Thread]