]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
threads: don't attempt to join threads with an id of 0
authorJason Ish <jason.ish@oisf.net>
Thu, 18 Apr 2024 06:33:09 +0000 (00:33 -0600)
committerVictor Julien <victor@inliniac.net>
Tue, 1 Apr 2025 08:17:04 +0000 (10:17 +0200)
Worker threads not created by Suricata, but instead a library user
should not be joined, as Suricata does not have access to their thread
handle, and it may in-fact be an unjoinable thread, such as the main
process.

When the thread ID is 0, assume the thread is "externally" managed,
but still mark is as dead to satisfy Suricata's view of the thread.

Ticket: #7240

src/tm-threads.c

index 75541f341c6f7ae160eafcf45ca9eb4a8c7be158..a1d74a80fbf270a9c6bdc5162f7538ea8a2bfa53 100644 (file)
@@ -1355,9 +1355,12 @@ static int TmThreadKillThread(ThreadVars *tv)
         }
     }
 
-    /* join it and flag it as dead */
-    pthread_join(tv->t, NULL);
-    SCLogDebug("thread %s stopped", tv->name);
+    /* Join the thread and flag as dead, unless the thread ID is 0 as
+     * its not a thread created by Suricata. */
+    if (tv->t) {
+        pthread_join(tv->t, NULL);
+        SCLogDebug("thread %s stopped", tv->name);
+    }
     TmThreadsSetFlag(tv, THV_DEAD);
     return 1;
 }