summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2003-01-14 03:36:45 +0000
committertjr <tjr@FreeBSD.org>2003-01-14 03:36:45 +0000
commitfc5f7e9a8b018cb40d5d12f0d66a7c7c40ed4c6f (patch)
treebbe801ccc4ea42a434e065d939a16f64c7ede171 /lib/libc
parent184d2efa56bcdd3b15ab5399f257c1285c02588e (diff)
downloadFreeBSD-src-fc5f7e9a8b018cb40d5d12f0d66a7c7c40ed4c6f.zip
FreeBSD-src-fc5f7e9a8b018cb40d5d12f0d66a7c7c40ed4c6f.tar.gz
Add the newly created semaphore to the named semaphore list in sem_open()
so that multiple opens of the same semaphore without an intervening sem_close() return the same object, and so that sem_close() does not segfault while trying to remove the item from the list.
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/gen/sem.c3
-rw-r--r--lib/libc/sys/sem.c3
2 files changed, 4 insertions, 2 deletions
diff --git a/lib/libc/gen/sem.c b/lib/libc/gen/sem.c
index fbed62a..d1cf10e 100644
--- a/lib/libc/gen/sem.c
+++ b/lib/libc/gen/sem.c
@@ -206,8 +206,9 @@ sem_open(const char *name, int oflag, ...)
*sem = sem_alloc(value, semid, 1);
if ((*sem) == NULL)
goto err;
- _pthread_mutex_unlock(&named_sems_mtx);
+ LIST_INSERT_HEAD(&named_sems, *sem, entry);
(*sem)->backpointer = sem;
+ _pthread_mutex_unlock(&named_sems_mtx);
return (sem);
err:
_pthread_mutex_unlock(&named_sems_mtx);
diff --git a/lib/libc/sys/sem.c b/lib/libc/sys/sem.c
index fbed62a..d1cf10e 100644
--- a/lib/libc/sys/sem.c
+++ b/lib/libc/sys/sem.c
@@ -206,8 +206,9 @@ sem_open(const char *name, int oflag, ...)
*sem = sem_alloc(value, semid, 1);
if ((*sem) == NULL)
goto err;
- _pthread_mutex_unlock(&named_sems_mtx);
+ LIST_INSERT_HEAD(&named_sems, *sem, entry);
(*sem)->backpointer = sem;
+ _pthread_mutex_unlock(&named_sems_mtx);
return (sem);
err:
_pthread_mutex_unlock(&named_sems_mtx);
OpenPOWER on IntegriCloud