]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Check for null hash or private while holding lock
authorTravis Cross <tc@traviscross.com>
Wed, 3 Sep 2014 19:42:25 +0000 (19:42 +0000)
committerTravis Cross <tc@traviscross.com>
Wed, 3 Sep 2014 19:45:45 +0000 (19:45 +0000)
What if the hash were destroyed by one thread holding the lock while
another thread was waiting for the lock?  The waiting thread would
have already checked that the hash was non-null and would proceed on
that assumption after acquiring the lock.

With this commit we check only after acquiring the lock.

ref: FS-6783
ref: FS-6775

src/mod/applications/mod_hash/mod_hash.c

index 133f05de3e6ddf98efdcd69e8d87d90aaf7903ec..fdc12bee2b077fe5b9820a9dcfda56b1da16a1f3 100644 (file)
@@ -280,12 +280,13 @@ SWITCH_LIMIT_RELEASE(limit_release_hash)
        limit_hash_private_t *pvt = switch_channel_get_private(channel, "limit_hash");
        limit_hash_item_t *item = NULL;
 
+       switch_thread_rwlock_wrlock(globals.limit_hash_rwlock);
+
        if (!pvt || !pvt->hash) {
+               switch_thread_rwlock_unlock(globals.limit_hash_rwlock);
                return SWITCH_STATUS_SUCCESS;
        }
 
-       switch_thread_rwlock_wrlock(globals.limit_hash_rwlock);
-
        /* clear for uuid */
        if (realm == NULL && resource == NULL) {
                switch_hash_index_t *hi = NULL;