Date: Sun, 7 May 2017 08:01:29 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r317899 - stable/10/lib/libc/gen Message-ID: <201705070801.v4781To1017855@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Sun May 7 08:01:29 2017 New Revision: 317899 URL: https://svnweb.freebsd.org/changeset/base/317899 Log: MFC r317610: Restructure normal (non-error) control flow in sem_close(). Modified: stable/10/lib/libc/gen/sem_new.c Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libc/gen/sem_new.c ============================================================================== --- stable/10/lib/libc/gen/sem_new.c Sun May 7 08:00:34 2017 (r317898) +++ stable/10/lib/libc/gen/sem_new.c Sun May 7 08:01:29 2017 (r317899) @@ -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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201705070801.v4781To1017855>