diff options
author | kib <kib@FreeBSD.org> | 2017-05-07 08:01:29 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2017-05-07 08:01:29 +0000 |
commit | cb5eb94f57844bb74cad947ecbe446fac0b2c6b0 (patch) | |
tree | 731b069dee10d59ee9f46dbad49456f0b5d4a210 /lib/libc | |
parent | fc3db99464193469bdaf8dfb285199d17c107b3e (diff) | |
download | FreeBSD-src-cb5eb94f57844bb74cad947ecbe446fac0b2c6b0.zip FreeBSD-src-cb5eb94f57844bb74cad947ecbe446fac0b2c6b0.tar.gz |
MFC r317610:
Restructure normal (non-error) control flow in sem_close().
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/gen/sem_new.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/lib/libc/gen/sem_new.c b/lib/libc/gen/sem_new.c index 691bc92..bceeead 100644 --- a/lib/libc/gen/sem_new.c +++ b/lib/libc/gen/sem_new.c @@ -41,6 +41,7 @@ #include <fcntl.h> #include <pthread.h> #include <stdarg.h> +#include <stdbool.h> #include <stdlib.h> #include <string.h> #include <time.h> @@ -259,6 +260,7 @@ int _sem_close(sem_t *sem) { struct sem_nameinfo *ni; + bool last; if (sem_check_validity(sem) != 0) return (-1); @@ -273,21 +275,17 @@ _sem_close(sem_t *sem) _pthread_mutex_lock(&sem_llock); LIST_FOREACH(ni, &sem_list, next) { if (sem == ni->sem) { - if (--ni->open_count > 0) { - _pthread_mutex_unlock(&sem_llock); - return (0); + last = --ni->open_count == 0; + if (last) + LIST_REMOVE(ni, next); + _pthread_mutex_unlock(&sem_llock); + if (last) { + munmap(sem, sizeof(*sem)); + free(ni); } - break; + return (0); } } - - if (ni != NULL) { - LIST_REMOVE(ni, next); - _pthread_mutex_unlock(&sem_llock); - munmap(sem, sizeof(*sem)); - free(ni); - return (0); - } _pthread_mutex_unlock(&sem_llock); errno = EINVAL; return (-1); |