Thread self-cancel only deals with the thread 85/299485/1
authorMichal Bloch <m.bloch@samsung.com>
Mon, 2 Oct 2023 11:32:12 +0000 (13:32 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Mon, 2 Oct 2023 13:50:19 +0000 (15:50 +0200)
Change-Id: I4c546d8e3479b7498c9ed2def85b7f710672b071

src/logger/logger.c

index a6f6e7b..bd35bff 100644 (file)
@@ -151,14 +151,9 @@ int add_reader_to_server(struct reader_common *reader, struct logger *server)
        return 0;
 }
 
-__attribute__((noreturn)) static void thread_seppuku(struct reader_common *reader)
+__attribute__((noreturn)) static void thread_seppuku(pthread_t self)
 {
-       const pthread_t self = reader->thread;
        assert(self == pthread_self());
-
-       reader->thread = 0; // make sure the destructor won't join the thread
-       reader_free(reader);
-
        pthread_detach(self); // since there's nobody to join us
        pthread_cancel(self);
        pthread_testcancel(); // force the cancel in case it didn't happen immediately
@@ -189,7 +184,11 @@ void reader_thread_finished(struct reader_common *reader)
                return;
 #endif
 
-       thread_seppuku(reader); // prevent a leak
+       const pthread_t self = reader->thread;
+       reader->thread = 0;
+       reader_free(reader);
+
+       thread_seppuku(self); // prevent a leak
        __builtin_unreachable();
 }