Module Name:    src
Committed By:   rmind
Date:           Tue Apr 12 20:37:26 UTC 2011

Modified Files:
        src/sys/kern: uipc_sem.c

Log Message:
do_ksem_open: do not leak the file descriptor on error path.
sys__ksem_unlink: fix comment, release one lock ealier.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/kern/uipc_sem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/uipc_sem.c
diff -u src/sys/kern/uipc_sem.c:1.30 src/sys/kern/uipc_sem.c:1.31
--- src/sys/kern/uipc_sem.c:1.30	Mon Apr 11 22:31:43 2011
+++ src/sys/kern/uipc_sem.c	Tue Apr 12 20:37:25 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: uipc_sem.c,v 1.30 2011/04/11 22:31:43 rmind Exp $	*/
+/*	$NetBSD: uipc_sem.c,v 1.31 2011/04/12 20:37:25 rmind Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.30 2011/04/11 22:31:43 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.31 2011/04/12 20:37:25 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -448,7 +448,8 @@
 		if ((oflag & O_CREAT) == 0) {
 			mutex_exit(&ksem_lock);
 			KASSERT(ksnew == NULL);
-			return ENOENT;
+			error = ENOENT;
+			goto err;
 		}
 
 		/* Check for the limit locked. */
@@ -549,9 +550,10 @@
 		return error;
 	}
 
-	/* Remove and destroy if no referenes. */
+	/* Remove from the global list. */
 	LIST_REMOVE(ks, ks_entry);
 	nsems--;
+	mutex_exit(&ksem_lock);
 
 	refcnt = ks->ks_ref;
 	if (refcnt) {
@@ -559,7 +561,6 @@
 		ks->ks_flags |= KS_UNLINKED;
 	}
 	mutex_exit(&ks->ks_lock);
-	mutex_exit(&ksem_lock);
 
 	if (refcnt == 0) {
 		ksem_free(ks);

Reply via email to