Fix double frees, remove_process now releases memory
Presence in singly-linked list strongly indicates that process is heap
allocated, and that if we are about to stop tracing it, we should also
reclaim the memory.
diff --git a/handle_event.c b/handle_event.c
index 5de61a6..7648248 100644
--- a/handle_event.c
+++ b/handle_event.c
@@ -374,7 +374,6 @@
event->e_un.ret_val);
}
remove_process(event->proc);
- free(event->proc);
}
static void
@@ -385,7 +384,6 @@
shortsignal(event->proc, event->e_un.signum));
}
remove_process(event->proc);
- free(event->proc);
}
static void
@@ -438,7 +436,6 @@
untrace:
untrace_pid(pid);
remove_process(proc);
- free(proc);
return;
}
output_line(proc, "--- Called exec() ---");
diff --git a/proc.h b/proc.h
index ed2bb70..443bd8e 100644
--- a/proc.h
+++ b/proc.h
@@ -193,7 +193,11 @@
void *data);
void change_process_leader(Process *proc, Process *leader);
-void remove_process(Process *proc);
+
+/* Remove process from the list of traced processes, drop any events
+ * in the event queue, destroy it and free memory. */
+void remove_process(struct Process *proc);
+
void install_event_handler(Process *proc, struct event_handler *handler);
void destroy_event_handler(Process *proc);
diff --git a/sysdeps/linux-gnu/ppc/plt.c b/sysdeps/linux-gnu/ppc/plt.c
index 7a88714..4a67ce8 100644
--- a/sysdeps/linux-gnu/ppc/plt.c
+++ b/sysdeps/linux-gnu/ppc/plt.c
@@ -821,10 +821,6 @@
if (proc->e_machine == EM_PPC64
&& bp->libsym != NULL
&& bp->libsym->arch.type == PPC_PLT_RESOLVED) {
- fprintf(stderr,
- "unresolve PLT:%p .plt:%#"PRIx64" orig:%#"PRIx64"\n",
- bp->addr, bp->libsym->arch.plt_slot_addr,
- bp->libsym->arch.resolved_value);
each_task(proc->leader, NULL, detach_task_cb, bp);
unresolve_plt_slot(proc, bp->libsym->arch.plt_slot_addr,
bp->libsym->arch.resolved_value);