From d3141403749e9d01f5d25114bcf1e4fa36f04a06 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 12 May 2006 15:33:49 +0000 Subject: [PATCH] cleanup git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1445 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_utils.h | 7 +++++ src/mod/endpoints/mod_exosip/mod_exosip.c | 27 +++++++++---------- .../mod_spidermonkey/mod_spidermonkey.c | 19 +++++++++++-- src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c | 6 +++-- src/switch_core.c | 5 +++- 5 files changed, 45 insertions(+), 19 deletions(-) diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index 92488462ce..0841b789cc 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -127,6 +127,13 @@ SWITCH_DECLARE(unsigned char) switch_char_to_rfc2833(char key); */ #define switch_copy_flags(dest, src, flags) (dest)->flags &= ~(flags); (dest)->flags |= ((src)->flags & (flags)) + +/*! + \brief Free a pointer and set it to NULL unles it already is NULL + \param it the pointer +*/ +#define switch_safe_free(it) if (it) {free(it);it=NULL;} + /*! \brief Test for NULL or zero length string \param s the string to test diff --git a/src/mod/endpoints/mod_exosip/mod_exosip.c b/src/mod/endpoints/mod_exosip/mod_exosip.c index 2a74355ed6..1dc878880f 100644 --- a/src/mod/endpoints/mod_exosip/mod_exosip.c +++ b/src/mod/endpoints/mod_exosip/mod_exosip.c @@ -30,6 +30,8 @@ * */ + + #define MY_EVENT_REGISTER "exosip::register" #define MY_EVENT_EXPIRE "exosip::expire" @@ -1361,6 +1363,10 @@ static switch_status_t exosip_create_call(eXosip_event_t * event) } } + switch_safe_free(dname); + switch_safe_free(drate); + switch_safe_free(dpayload); + if (activate_rtp(tech_pvt) != SWITCH_STATUS_SUCCESS) { exosip_on_hangup(session); switch_core_session_destroy(&session); @@ -1493,10 +1499,8 @@ static void handle_message_new(eXosip_event_t *je) if (osip_message_get_contact(je->request, x++, &contact) < 0) { break; } - if (lame) { - free(lame); - lame = NULL; - } + + switch_safe_free(lame); osip_contact_to_str((const osip_contact_t *) contact, &lame); contact_uri = osip_contact_get_url(contact); @@ -1544,11 +1548,8 @@ static void handle_message_new(eXosip_event_t *je) } } - - } else { - /* Unimplemented */ - } - + switch_safe_free(lame); + } } @@ -1650,9 +1651,9 @@ static void handle_answer(eXosip_event_t * event) eXosip_call_send_ack(event->did, ack); eXosip_unlock(); - free(dname); - free(drate); - free(dpayload); + switch_safe_free(dname); + switch_safe_free(drate); + switch_safe_free(dpayload); if (activate_rtp(tech_pvt) != SWITCH_STATUS_SUCCESS) { @@ -2018,8 +2019,6 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void) break; case EXOSIP_CALL_INVITE: if (exosip_create_call(event) != SWITCH_STATUS_SUCCESS) { - - destroy_call_by_event(event); } break; diff --git a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c index f57719f3c4..896c1b2f6e 100644 --- a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c +++ b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c @@ -661,11 +661,18 @@ static JSBool session_hangup(JSContext *cx, JSObject *obj, uintN argc, jsval *ar { struct js_session *jss = JS_GetPrivate(cx, obj); switch_channel_t *channel; + char *cause_name = NULL; + switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING; + + if (argc > 1) { + cause_name = JS_GetStringBytes(JS_ValueToString(cx, argv[0])); + cause = switch_channel_str2cause(cause_name); + } channel = switch_core_session_get_channel(jss->session); assert(channel != NULL); - switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); + switch_channel_hangup(channel, cause); switch_core_session_kill_channel(jss->session, SWITCH_SIG_KILL); return JS_TRUE; } @@ -747,7 +754,7 @@ static JSBool js_fetchurl_hash(JSContext *cx, JSObject *obj, uintN argc, jsval * url = JS_GetStringBytes(JS_ValueToString(cx, argv[0])); name = JS_GetStringBytes(JS_ValueToString(cx, argv[1])); - curl_global_init(CURL_GLOBAL_ALL); + curl_handle = curl_easy_init(); if (!strncasecmp(url, "https", 5)) { curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0); @@ -2206,6 +2213,14 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod /* connect my internal structure to the blank pointer passed to me */ *module_interface = &spidermonkey_module_interface; + curl_global_init(CURL_GLOBAL_ALL); + /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS; } + +SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void) +{ + curl_global_cleanup(); + return SWITCH_STATUS_SUCCESS; +} diff --git a/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c b/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c index 8243ae884d..5b19ac0676 100644 --- a/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c +++ b/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c @@ -77,13 +77,12 @@ static switch_xml_t xml_url_fetch(char *section, char url[1024] = "", filename[1024] = ""; CURL *curl_handle = NULL; struct config_data config_data; - switch_xml_t xml; + switch_xml_t xml = NULL; snprintf(url, sizeof(url), "%s?section=%s&tag_name=%s&key_name=%s&key_value=%s%s%s\n", globals.url, section, tag_name, key_name, key_value, params ? "&" : "", params ? params : ""); srand((unsigned int)(time(NULL) + strlen(url))); snprintf(filename, sizeof(filename), "%s%04x.tmp", SWITCH_GLOBAL_dirs.temp_dir, (rand() & 0xffff)); - curl_global_init(CURL_GLOBAL_ALL); curl_handle = curl_easy_init(); if (!strncasecmp(url, "https", 5)) { curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0); @@ -172,6 +171,8 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod switch_xml_bind_search_function(xml_url_fetch); } + curl_global_init(CURL_GLOBAL_ALL); + /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS; } @@ -306,6 +307,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void) SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void) { globals.running = 0; + curl_global_cleanup(); return SWITCH_STATUS_SUCCESS; } diff --git a/src/switch_core.c b/src/switch_core.c index 02d7dbcee8..8cdc546f6a 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -2535,7 +2535,9 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread, switch_time_t last_commit = switch_time_now(); uint32_t freq = 1000, target = 500, diff = 0; - runtime.event_db = switch_core_db_handle(); + if (!runtime.event_db) { + runtime.event_db = switch_core_db_handle(); + } switch_queue_create(&runtime.sql_queue, SWITCH_SQL_QUEUE_LEN, runtime.memory_pool); for(;;) { @@ -2880,6 +2882,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_destroy(void) switch_yield(1000); } switch_core_db_close(runtime.db); + switch_core_db_close(runtime.event_db); switch_xml_destroy(); if (runtime.memory_pool) {