From 4f61d04fd875738269e8ba5c57aac378c2d5051e Mon Sep 17 00:00:00 2001 From: gonzo Date: Tue, 10 Jun 2008 20:55:10 +0000 Subject: [PATCH] Keep proper track of nsegs counter: sem_free is called for all allocated semaphores, so it's wrong to increase it conditionally, in this case for every over-the-limit semaphore nsegs is decreased without being previously increased. PR: kern/123685 Approved by: cognet (mentor) --- sys/kern/uipc_sem.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sys/kern/uipc_sem.c b/sys/kern/uipc_sem.c index c0406134335a..a91096ffb3f9 100644 --- a/sys/kern/uipc_sem.c +++ b/sys/kern/uipc_sem.c @@ -221,14 +221,13 @@ sem_create(struct thread *td, const char *name, struct ksem **ksret, sem_enter(td->td_proc, ret); *ksret = ret; mtx_lock(&sem_lock); - if (nsems >= p31b_getcfg(CTL_P1003_1B_SEM_NSEMS_MAX)) { + nsems++; + if (nsems > p31b_getcfg(CTL_P1003_1B_SEM_NSEMS_MAX)) { sem_leave(td->td_proc, ret); sem_free(ret); error = ENFILE; - } else { - nsems++; + } else error = 0; - } mtx_unlock(&sem_lock); return (error); }