]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Check for null hash on increment of mod_hash limit
authorTravis Cross <tc@traviscross.com>
Thu, 11 Sep 2014 17:42:07 +0000 (17:42 +0000)
committerTravis Cross <tc@traviscross.com>
Thu, 11 Sep 2014 17:47:57 +0000 (17:47 +0000)
When we specifically release all limits on a channel we destroy the
hash table stored in the "limit_hash" private channel data but we
don't destroy the private data as it will be reclaimed as part of the
session.  If limit increment is called after the limit release we can
reuse that channel private, but we need to check whether the hash
table is null first.  Fortunately this makes the code look better
anyway.

FS-6775 #resolve
FS-6783 #resolve

src/mod/applications/mod_hash/mod_hash.c

index fdc12bee2b077fe5b9820a9dcfda56b1da16a1f3..2ab9e0ae7decc0c97d6f6a58c94f0795a5cfcdd4 100644 (file)
@@ -150,21 +150,15 @@ SWITCH_LIMIT_INCR(limit_incr_hash)
                switch_core_hash_insert(globals.limit_hash, hashkey, item);
        }
 
-       /* Did we already run on this channel before? */
-       if ((pvt = switch_channel_get_private(channel, "limit_hash"))) {
-               /* Yes, but check if we did that realm+resource
-                  If we didnt, allow incrementing the counter.
-                  If we did, dont touch it but do the validation anyways
-                */
-               increment = !switch_core_hash_find(pvt->hash, hashkey);
-       } else {
-               /* This is the first limit check on this channel, create a hashtable, set our private data */
+       if (!(pvt = switch_channel_get_private(channel, "limit_hash"))) {
                pvt = (limit_hash_private_t *) switch_core_session_alloc(session, sizeof(limit_hash_private_t));
                memset(pvt, 0, sizeof(limit_hash_private_t));
-               switch_core_hash_init(&pvt->hash);
                switch_channel_set_private(channel, "limit_hash", pvt);
        }
-
+       if (!(pvt->hash)) {
+               switch_core_hash_init(&pvt->hash);
+       }
+       increment = !switch_core_hash_find(pvt->hash, hashkey);
        remote_usage = get_remote_usage(hashkey);
 
        if (interval > 0) {