]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-2973 Fix possible segfaults and memory leak during unload, and add new setting...
authorJeff Lenk <jeff@jefflenk.com>
Fri, 21 Jan 2011 15:09:53 +0000 (09:09 -0600)
committerJeff Lenk <jeff@jefflenk.com>
Fri, 21 Jan 2011 15:09:53 +0000 (09:09 -0600)
conf/autoload_configs/easyroute.conf.xml
src/mod/applications/mod_easyroute/mod_easyroute.c

index 7cd490942f331a0cc660e66e356c81536ea79c9f..350a50989b0443cf9d60eb7eefba28788b746a62 100644 (file)
@@ -11,6 +11,9 @@
     <!-- IP or Hostname of Default Route -->
     <param name="default-gateway" value="192.168.66.6"/>
 
+    <!-- Number of times to retry ODBC connection on connection problems, default is 120 -->
+    <param name="odbc-retries" value="120"/>
+
     <!-- Customer Query. Use this with Care!!! We are not responsible if you mess
          This up!!! Query *MUST* return columns in the following order!
         gateway varchar(128) - contains destination gateway host:port pair (ex: 192.168.1.1:5060 )
index 481df958cf95f3b4f88ade6235c319e2af9c5c81..75b4712f2d1c9bbcb5001df5cd18d468b61ede81 100644 (file)
@@ -65,6 +65,7 @@ static struct {
        switch_mutex_t *mutex;
        char *custom_query;
        switch_odbc_handle_t *master_odbc;
+       int odbc_num_retries;
 } globals;
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_easyroute_load);
@@ -120,6 +121,8 @@ static switch_status_t load_config(void)
                                set_global_default_gateway(val);
                        } else if (!strcasecmp(var, "custom-query")) {
                                set_global_custom_query(val);
+                       } else if (!strcasecmp(var, "odbc-retries")) {
+                               globals.odbc_num_retries = atoi(val);
                        }
                }
        }
@@ -143,6 +146,9 @@ static switch_status_t load_config(void)
                } else {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opened ODBC Database!\n");
                }
+               if (globals.odbc_num_retries) {
+                       switch_odbc_set_num_retries(globals.master_odbc, globals.odbc_num_retries);
+               }
                if (switch_odbc_handle_connect(globals.master_odbc) != SWITCH_ODBC_SUCCESS) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
                        status = SWITCH_STATUS_FALSE;
@@ -205,7 +211,7 @@ static switch_status_t route_lookup(char *dn, easyroute_results_t *results, int
                switch_mutex_lock(globals.mutex);
        }
        /* Do the Query */
-       if (switch_odbc_handle_callback_exec(globals.master_odbc, sql, route_callback, &pdata, NULL) == SWITCH_ODBC_SUCCESS) {
+       if (globals.master_odbc && switch_odbc_handle_callback_exec(globals.master_odbc, sql, route_callback, &pdata, NULL) == SWITCH_ODBC_SUCCESS) {
                char tmp_profile[129];
                char tmp_gateway[129];
 
@@ -418,7 +424,10 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_easyroute_load)
 
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_easyroute_shutdown)
 {
-       switch_odbc_handle_disconnect(globals.master_odbc);
+       if (globals.master_odbc) {
+               switch_odbc_handle_disconnect(globals.master_odbc);
+               switch_odbc_handle_destroy(&globals.master_odbc);
+       }
        switch_safe_free(globals.db_username);
        switch_safe_free(globals.db_password);
        switch_safe_free(globals.db_dsn);