diff options
author | Rich Felker <dalias@aerifal.cx> | 2023-02-11 19:09:53 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2023-02-12 15:05:38 -0500 |
commit | 711673ee772e20a74aaf301c2d7745c20c4f4d47 (patch) | |
tree | 6ee7a2e70cc9b3156942f1aec5240a32c22d73f1 | |
parent | 8c0c9c69a12acc0a82590d4fd64cf633ff1dedd2 (diff) | |
download | musl-711673ee772e20a74aaf301c2d7745c20c4f4d47.tar.gz musl-711673ee772e20a74aaf301c2d7745c20c4f4d47.tar.xz musl-711673ee772e20a74aaf301c2d7745c20c4f4d47.zip |
mq_notify: join worker thread before returning in error path
this avoids leaving behind transient resource consumption whose cleanup is subject to scheduling behavior.
-rw-r--r-- | src/mq/mq_notify.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/mq/mq_notify.c b/src/mq/mq_notify.c index 217d8888..8109dfb2 100644 --- a/src/mq/mq_notify.c +++ b/src/mq/mq_notify.c @@ -35,6 +35,7 @@ static void *start(void *p) sem_post(&args->sem); if (err) return 0; + pthread_detach(pthread_self()); n = recv(s, buf, sizeof(buf), MSG_NOSIGNAL|MSG_WAITALL); close(s); if (n==sizeof buf && buf[sizeof buf - 1] == 1) @@ -60,7 +61,7 @@ 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); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); sem_init(&args.sem, 0, 0); if (pthread_create(&td, &attr, start, &args)) { @@ -71,14 +72,16 @@ int mq_notify(mqd_t mqd, const struct sigevent *sev) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); sem_wait(&args.sem); - pthread_setcancelstate(cs, 0); sem_destroy(&args.sem); if (args.err) { __syscall(SYS_close, s); + pthread_join(td, 0); + pthread_setcancelstate(cs, 0); errno = args.err; return -1; } + pthread_setcancelstate(cs, 0); return 0; } |