]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_cidlookup] Fix dereference of null pointer and optimize use of pool's memory... 442/head
authorAndrey Volk <andywolk@gmail.com>
Wed, 26 Feb 2020 12:12:32 +0000 (16:12 +0400)
committerAndrey Volk <andywolk@gmail.com>
Wed, 26 Feb 2020 12:12:32 +0000 (16:12 +0400)
src/mod/applications/mod_cidlookup/mod_cidlookup.c

index 5b90e8a095a34f7e5849d5e1b28b3e370e8eb83c..7df22fb3ef2d1b5800ecef59bddf9c0a6375285f 100644 (file)
@@ -545,9 +545,6 @@ static cid_data_t *do_lookup(switch_memory_pool_t *pool, switch_event_t *event,
        cid_data_t *cidtmp = NULL;
        switch_bool_t save_cache = SWITCH_FALSE;
 
-       cid = switch_core_alloc(pool, sizeof(cid_data_t));
-       switch_assert(cid);
-
        number = string_digitsonly(pool, num);
        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "caller_id_number", number);
 
@@ -555,6 +552,8 @@ static cid_data_t *do_lookup(switch_memory_pool_t *pool, switch_event_t *event,
        if (globals.odbc_dsn && globals.sql) {
                name = do_db_lookup(pool, event, number, globals.sql);
                if (name) {
+                       cid = switch_core_alloc(pool, sizeof(cid_data_t));
+                       switch_assert(cid);
                        cid->name = name;
                        cid->src = "phone_database";
                        goto done;
@@ -578,6 +577,11 @@ static cid_data_t *do_lookup(switch_memory_pool_t *pool, switch_event_t *event,
                }
        }
 
+       if (!cid) {
+               cid = switch_core_alloc(pool, sizeof(cid_data_t));
+               switch_assert(cid);
+       }
+
        if (!skipurl && globals.url) {
                url_query = switch_event_expand_headers(event, globals.url);
                do_lookup_url(pool, event, &name, url_query, NULL, NULL, 0);
@@ -593,10 +597,6 @@ static cid_data_t *do_lookup(switch_memory_pool_t *pool, switch_event_t *event,
        }
 
   done:
-       if (!cid) {
-               cid = switch_core_alloc(pool, sizeof(cid_data_t));
-               switch_assert(cid);
-       }
        /* append area if we can */
        if (!cid->area && !skipcitystate && strlen(number) == 11 && number[0] == '1' && globals.odbc_dsn && globals.citystate_sql) {