summaryrefslogtreecommitdiff
path: root/sem_timedwait.c
diff options
context:
space:
mode:
Diffstat (limited to 'sem_timedwait.c')
-rw-r--r--sem_timedwait.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/sem_timedwait.c b/sem_timedwait.c
index deefa6e..52146b4 100644
--- a/sem_timedwait.c
+++ b/sem_timedwait.c
@@ -137,6 +137,8 @@ sem_timedwait (sem_t * sem, const struct timespec *abstime)
int result = 0;
sem_t s = *sem;
+ pthread_testcancel();
+
if (sem == NULL)
{
result = EINVAL;
@@ -157,11 +159,20 @@ sem_timedwait (sem_t * sem, const struct timespec *abstime)
milliseconds = ptw32_relmillisecs (abstime);
}
- pthread_testcancel();
-
if ((result = pthread_mutex_lock (&s->lock)) == 0)
{
- int v = --s->value;
+ int v;
+
+ /* See sem_destroy.c
+ */
+ if (*sem == NULL)
+ {
+ (void) pthread_mutex_unlock (&s->lock);
+ errno = EINVAL;
+ return -1;
+ }
+
+ v = --s->value;
(void) pthread_mutex_unlock (&s->lock);
if (v < 0)
@@ -192,6 +203,13 @@ sem_timedwait (sem_t * sem, const struct timespec *abstime)
if (!timedout && pthread_mutex_lock (&s->lock) == 0)
{
+ if (*sem == NULL)
+ {
+ (void) pthread_mutex_unlock (&s->lock);
+ errno = EINVAL;
+ return -1;
+ }
+
if (s->leftToUnblock > 0)
{
--s->leftToUnblock;