Fix a race condition 32/299432/1
authorMichal Bloch <m.bloch@samsung.com>
Mon, 25 Sep 2023 11:58:32 +0000 (13:58 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Wed, 27 Sep 2023 13:20:53 +0000 (15:20 +0200)
Change-Id: I4c546d8e3479b7498c9ed2def85b7f710672b059

src/logger/reader_common.c

index a654476..3b69435 100644 (file)
@@ -126,12 +126,12 @@ int reader_run(struct reader_common *const reader)
        if (!reader->ops->thread_func)
                return -ENOENT;
 
-       pthread_t thread;
-       int r = pthread_create(&thread, NULL, reader->ops->thread_func, reader);
-       if (r < 0)
+       int r = pthread_create(&reader->thread, NULL, reader->ops->thread_func, reader);
+       if (r < 0) {
+               reader->thread = 0;
                return r;
+       }
 
-       reader->thread = thread;
        return 0;
 }