Code

utils channel: Unlock mutex before returning on error.
authorSebastian Harl <sh@tokkee.org>
Sun, 20 Oct 2013 20:20:36 +0000 (22:20 +0200)
committerSebastian Harl <sh@tokkee.org>
Sun, 20 Oct 2013 20:20:36 +0000 (22:20 +0200)
src/utils/channel.c

index 6db9b9512310b8d626ea12f73e33e90a5ff3d34e..af41b477b4748252763123b8a0303aa5edc06676 100644 (file)
@@ -202,8 +202,10 @@ sdb_channel_select(sdb_channel_t *chan, int *wantread, void *read_data,
                if (timeout) {
                        struct timespec abstime;
 
-                       if (clock_gettime(CLOCK_REALTIME, &abstime))
+                       if (clock_gettime(CLOCK_REALTIME, &abstime)) {
+                               pthread_mutex_unlock(&chan->lock);
                                return -1;
+                       }
 
                        abstime.tv_sec += timeout->tv_sec;
                        abstime.tv_nsec += timeout->tv_nsec;
@@ -214,8 +216,8 @@ sdb_channel_select(sdb_channel_t *chan, int *wantread, void *read_data,
                else
                        status = pthread_cond_wait(&chan->cond, &chan->lock);
        }
-
        pthread_mutex_unlock(&chan->lock);
+
        if (status) {
                errno = status;
                return -1;