From f70375df85d26235a45e74559afd69be59e5ff99 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 28 Oct 2020 16:13:45 -0400 Subject: fix sem_close unmapping of still-referenced semaphore sem_open is required to return the same sem_t pointer for all references to the same named semaphore when it's opened more than once in the same process. thus we keep a table of all the mapped semaphores and their reference counts. the code path for sem_close checked the reference count, but then proceeded to unmap the semaphore regardless of whether the count had reached zero. add an immediate unlock-and-return for the nonzero refcnt case so the property of performing the munmap syscall after releasing the lock can be preserved. --- src/thread/sem_open.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/thread/sem_open.c b/src/thread/sem_open.c index de8555c5..6fb0c5b2 100644 --- a/src/thread/sem_open.c +++ b/src/thread/sem_open.c @@ -163,10 +163,12 @@ int sem_close(sem_t *sem) int i; LOCK(lock); for (i=0; i