[PATCH] irmd: Fix cleanup of shm_flow_set

  • From: Dimitri Staessens <dimitri@ouroboros.rocks>
  • To: ouroboros@xxxxxxxxxxxxx
  • Date: Wed, 18 Mar 2020 21:53:21 +0100

The shm_flowset destroy was using the irmd pid, resulting in wrong
unlinks. The irmd was not cleaning up the process table, resulting in
shm leaks if there were still running processes on exit.

Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks>
---
 src/irmd/main.c        | 8 ++++++++
 src/lib/shm_flow_set.c | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/irmd/main.c b/src/irmd/main.c
index 940432f..d4d6445 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -1780,6 +1780,14 @@ static void irm_fini(void)
                 prog_entry_destroy(e);
         }
 
+        list_for_each_safe(p, h, &irmd.proc_table) {
+                struct proc_entry * e = list_entry(p, struct proc_entry, next);
+                list_del(&e->next);
+                e->state = PROC_INIT; /* sanitizer already joined */
+                proc_entry_destroy(e);
+                free(e);
+        }
+
         registry_destroy(&irmd.registry);
 
         pthread_rwlock_unlock(&irmd.reg_lock);
diff --git a/src/lib/shm_flow_set.c b/src/lib/shm_flow_set.c
index c19adaf..0f701b6 100644
--- a/src/lib/shm_flow_set.c
+++ b/src/lib/shm_flow_set.c
@@ -148,7 +148,7 @@ struct shm_flow_set * shm_flow_set_create(pid_t pid)
         if (set == NULL)
                 goto fail_set;
 
-        set->pid = getpid();
+        set->pid = pid;
 
         if (pthread_mutexattr_init(&mattr))
                 goto fail_mutexattr_init;
-- 
2.25.1


Other related posts:

  • » [PATCH] irmd: Fix cleanup of shm_flow_set - Dimitri Staessens