aboutsummaryrefslogtreecommitdiff
path: root/proc.c
diff options
context:
space:
mode:
authorPetr Machata <pmachata@redhat.com>2012-10-26 22:25:33 +0200
committerPetr Machata <pmachata@redhat.com>2012-10-26 22:25:33 +0200
commite0e89edff4ff9216a9a8631b078858851a15f0e7 (patch)
tree11cb0410b13a2b0e96a4050055017d6189b8114c /proc.c
parente677c7e0b79fc0af7c98436d924fefca7d43f359 (diff)
downloadltrace-e0e89edff4ff9216a9a8631b078858851a15f0e7.tar.gz
Pop remaining stack before the process exits
This plugs a leak
Diffstat (limited to 'proc.c')
-rw-r--r--proc.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/proc.c b/proc.c
index 3a452ab..9fefc0e 100644
--- a/proc.c
+++ b/proc.c
@@ -180,10 +180,28 @@ destroy_breakpoint_cb(struct Process *proc, struct breakpoint *bp, void *data)
return CBS_CONT;
}
+// XXX see comment in handle_event.c
+void callstack_pop(struct Process *proc);
+
static void
-private_process_destroy(struct Process *proc, int keep_filename)
+private_process_destroy(struct Process *proc, int was_exec)
{
- if (!keep_filename)
+ /* Pop remaining stack elements. */
+ while (proc->callstack_depth > 0) {
+ /* When this is called just before a process is
+ * destroyed, the breakpoints should either have been
+ * retracted by now, or were killed by exec. In any
+ * case, it's safe to pretend that there are no
+ * breakpoints associated with the stack elements, so
+ * that stack_pop doesn't attempt to destroy them. */
+ size_t i = proc->callstack_depth - 1;
+ if (!proc->callstack[i].is_syscall)
+ proc->callstack[i].return_addr = 0;
+
+ callstack_pop(proc);
+ }
+
+ if (!was_exec)
free(proc->filename);
/* Libraries and symbols. This is only relevant in