>From 1e9313fec1c666be2d2a3013aa0f34ed0e166c45 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Fri, 10 Feb 2023 11:27:18 -0500 Subject: [PATCH 3/3] mq_notify: join worker thread before returning in error path this avoids leaving behind transient resource consumption whose cleanup is subject to scheduling behavior. --- src/mq/mq_notify.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mq/mq_notify.c b/src/mq/mq_notify.c index a42e6afc..31538880 100644 --- a/src/mq/mq_notify.c +++ b/src/mq/mq_notify.c @@ -54,7 +54,6 @@ int mq_notify(mqd_t mqd, const struct sigevent *sev) if (sev->sigev_notify_attributes) attr = *sev->sigev_notify_attributes; else pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); sem_init(&args.sem, 0, 0); if (pthread_create(&td, &attr, start, &args)) { @@ -72,8 +71,10 @@ int mq_notify(mqd_t mqd, const struct sigevent *sev) if (syscall(SYS_mq_notify, mqd, &sev2) < 0) { pthread_cancel(td); + pthread_join(td, 0); return -1; } + pthread_detach(td); return 0; } -- 2.21.0