summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--semaphore.c11
2 files changed, 11 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 93d5d80..2e27f6a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,7 +5,10 @@
* semaphore.c (sem_init): Fix typo and missing bracket
in conditionally compiled code. Only older versions of
WinCE require this code, hence it doesn't normally get
- tested.
+ tested; somehow when sem_t reverted to an opaque struct
+ the calloc NULL check was left in the conditionally included
+ section.
+ (sem_destroy): Likewise, the calloced sem_t wasn't being freed.
2001-10-25 Ross Johnson <rpj@setup1.ise.canberra.edu.au>
diff --git a/semaphore.c b/semaphore.c
index 1e23285..0dc9ed9 100644
--- a/semaphore.c
+++ b/semaphore.c
@@ -90,14 +90,16 @@ sem_init (sem_t * sem, int pshared, unsigned int value)
}
else
{
- s = (sem_t) calloc (1, sizeof (*s));
-#ifdef NEED_SEM
+ s = (sem_t) calloc (1, sizeof (*s));
if (NULL == s)
{
result = ENOMEM;
}
+
+#ifdef NEED_SEM
+
else
{
s->value = value;
@@ -184,7 +186,7 @@ sem_destroy (sem_t * sem)
}
else
{
- s = *sem;
+ s = *sem;
*sem = NULL;
#ifdef NEED_SEM
@@ -197,7 +199,6 @@ sem_destroy (sem_t * sem)
else
{
DeleteCriticalSection(&s->sem_lock_cs);
- free(s);
}
#else /* NEED_SEM */
@@ -218,6 +219,8 @@ sem_destroy (sem_t * sem)
return -1;
}
+ free(s);
+
return 0;
} /* sem_destroy */