[Freeswitch-trunk] [freeswitch] FreeSWITCH Source branch master updated. git2svn-syncpoint-master-1687-g4ae8282

git at svn.freeswitch.org git at svn.freeswitch.org
Thu Feb 3 00:54:47 MSK 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "FreeSWITCH Source".

The branch, master has been updated
       via  4ae8282e6c6df0e296113e9b4b4a1383e1af8ad7 (commit)
      from  89c5f3bf8226bf605336b66e7761fd9f753d935a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 4ae8282e6c6df0e296113e9b4b4a1383e1af8ad7
Author: Anthony Minessale <anthm at freeswitch.org>
Date:   Wed Feb 2 15:43:26 2011 -0600

    fix possible bad pointer in global vars (please test)

diff --git a/src/include/private/switch_core_pvt.h b/src/include/private/switch_core_pvt.h
index 30690b1..05cd24d 100644
--- a/src/include/private/switch_core_pvt.h
+++ b/src/include/private/switch_core_pvt.h
@@ -246,6 +246,7 @@ struct switch_runtime {
 	int sql_buffer_len;
 	int max_sql_buffer_len;
 	switch_dbtype_t odbc_dbtype;
+	char hostname[256];
 };
 
 extern struct switch_runtime runtime;
diff --git a/src/include/switch_core.h b/src/include/switch_core.h
index 109a169..69b0642 100644
--- a/src/include/switch_core.h
+++ b/src/include/switch_core.h
@@ -759,6 +759,9 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_force_locate(_In_z_
   \return the value of the desired variable
 */
 SWITCH_DECLARE(char *) switch_core_get_variable(_In_z_ const char *varname);
+SWITCH_DECLARE(char *) switch_core_get_variable_dup(_In_z_ const char *varname);
+SWITCH_DECLARE(char *) switch_core_get_variable_pdup(_In_z_ const char *varname, switch_memory_pool_t *pool);
+SWITCH_DECLARE(const char *) switch_core_get_hostname(void);
 
 /*! 
   \brief Add a global variable to the core
diff --git a/src/include/switch_nat.h b/src/include/switch_nat.h
index bdbd51b..9e40546 100644
--- a/src/include/switch_nat.h
+++ b/src/include/switch_nat.h
@@ -49,7 +49,7 @@ typedef enum {
 	SWITCH_NAT_TCP
 } switch_nat_ip_proto_t;
 
-
+SWITCH_DECLARE(const char *) switch_nat_get_type(void);
 
 /*! 
   \brief Initilize the NAT Traversal System
diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c
index 7771b09..807770a 100644
--- a/src/mod/applications/mod_commands/mod_commands.c
+++ b/src/mod/applications/mod_commands/mod_commands.c
@@ -349,7 +349,7 @@ SWITCH_STANDARD_API(timer_test_function)
 
 SWITCH_STANDARD_API(group_call_function)
 {
-	char *domain;
+	char *domain, *dup_domain = NULL;
 	char *group_name = NULL;
 	char *flags;
 	int ok = 0;
@@ -392,7 +392,9 @@ SWITCH_STANDARD_API(group_call_function)
 	if (domain) {
 		*domain++ = '\0';
 	} else {
-		domain = switch_core_get_variable("domain");
+		if ((dup_domain = switch_core_get_variable_dup("domain"))) {
+			domain = dup_domain;
+		}
 	}
 
 	if (!zstr(domain)) {
@@ -544,13 +546,14 @@ SWITCH_STANDARD_API(group_call_function)
 	}
 
   end:
-
+	
 	switch_safe_free(group_name);
+	switch_safe_free(dup_domain);
 
 	if (!ok) {
 		stream->write_function(stream, "error/NO_ROUTE_DESTINATION");
 	}
-
+	
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -559,7 +562,7 @@ SWITCH_STANDARD_API(in_group_function)
 {
 	switch_xml_t x_domain, xml = NULL, x_user = NULL, x_group;
 	int argc;
-	char *mydata = NULL, *argv[2], *user, *domain;
+	char *mydata = NULL, *argv[2], *user, *domain, *dup_domain = NULL;
 	char delim = ',';
 	switch_event_t *params = NULL;
 	const char *rval = "false";
@@ -579,7 +582,9 @@ SWITCH_STANDARD_API(in_group_function)
 	if ((domain = strchr(user, '@'))) {
 		*domain++ = '\0';
 	} else {
-		domain = switch_core_get_variable("domain");
+		if ((dup_domain = switch_core_get_variable_dup("domain"))) {
+			domain = dup_domain;
+		}
 	}
 
 	switch_event_create(&params, SWITCH_EVENT_REQUEST_PARAMS);
@@ -601,6 +606,7 @@ SWITCH_STANDARD_API(in_group_function)
 
 	switch_xml_free(xml);
 	switch_safe_free(mydata);
+	switch_safe_free(dup_domain);
 	switch_event_destroy(&params);
 
 	return SWITCH_STATUS_SUCCESS;
@@ -610,7 +616,7 @@ SWITCH_STANDARD_API(user_data_function)
 {
 	switch_xml_t x_domain, xml = NULL, x_user = NULL, x_group = NULL, x_param, x_params;
 	int argc;
-	char *mydata = NULL, *argv[3], *key = NULL, *type = NULL, *user, *domain;
+	char *mydata = NULL, *argv[3], *key = NULL, *type = NULL, *user, *domain, *dup_domain = NULL;
 	char delim = ' ';
 	const char *container = "params", *elem = "param";
 	const char *result = NULL;
@@ -631,7 +637,9 @@ SWITCH_STANDARD_API(user_data_function)
 	if ((domain = strchr(user, '@'))) {
 		*domain++ = '\0';
 	} else {
-		if (!(domain = switch_core_get_variable("domain"))) {
+		if ((dup_domain = switch_core_get_variable("domain"))) {
+			domain = dup_domain;
+		} else {
 			domain = "cluecon.com";
 		}
 	}
@@ -694,6 +702,7 @@ SWITCH_STANDARD_API(user_data_function)
 	}
 	switch_xml_free(xml);
 	switch_safe_free(mydata);
+	switch_safe_free(dup_domain);
 	switch_event_destroy(&params);
 
 	return SWITCH_STATUS_SUCCESS;
@@ -4375,7 +4384,9 @@ SWITCH_STANDARD_API(global_getvar_function)
 	if (zstr(cmd)) {
 		switch_core_dump_variables(stream);
 	} else {
-		stream->write_function(stream, "%s", switch_str_nil(switch_core_get_variable(cmd)));
+		char *var = switch_core_get_variable_dup(cmd);
+		stream->write_function(stream, "%s", switch_str_nil(var));
+		switch_safe_free(var);
 	}
 	return SWITCH_STATUS_SUCCESS;
 }
diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c
index 928a9b8..4be2a64 100755
--- a/src/mod/applications/mod_dptools/mod_dptools.c
+++ b/src/mod/applications/mod_dptools/mod_dptools.c
@@ -2787,7 +2787,7 @@ static switch_call_cause_t group_outgoing_channel(switch_core_session_t *session
 	if ((domain = strchr(group, '@'))) {
 		*domain++ = '\0';
 	} else {
-		domain = switch_core_get_variable("domain");
+		domain = switch_core_get_variable_pdup("domain", switch_core_session_get_pool(session));
 	}
 
 	if (!domain) {
@@ -2908,7 +2908,7 @@ static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session,
 	if ((domain = strchr(user, '@'))) {
 		*domain++ = '\0';
 	} else {
-		domain = switch_core_get_variable("domain");
+		domain = switch_core_get_variable_pdup("domain", switch_core_session_get_pool(session));
 	}
 
 	if (!domain) {
@@ -3193,10 +3193,11 @@ static switch_status_t event_chat_send(const char *proto, const char *from, cons
 		if (body)
 			switch_event_add_body(event, "%s", body);
 		if (to) {
-			const char *v;
+			char *v;
 			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "To", to);
-			if ((v = switch_core_get_variable(to))) {
+			if ((v = switch_core_get_variable_dup(to))) {
 				switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Command", v);
+				free(v);
 			}
 		}
 
@@ -3214,15 +3215,15 @@ static switch_status_t api_chat_send(const char *proto, const char *from, const
 									 const char *body, const char *type, const char *hint)
 {
 	if (to) {
-		const char *v;
+		char *v = NULL;
 		switch_stream_handle_t stream = { 0 };
 		char *cmd = NULL, *arg;
 
-		if (!(v = switch_core_get_variable(to))) {
-			v = to;
+		if (!(v = switch_core_get_variable_dup(to))) {
+			v = strdup(to);
 		}
 
-		cmd = strdup(v);
+		cmd = v;
 		switch_assert(cmd);
 
 		switch_url_decode(cmd);
diff --git a/src/mod/applications/mod_redis/mod_redis.c b/src/mod/applications/mod_redis/mod_redis.c
index 1e99967..ebf2a9e 100755
--- a/src/mod/applications/mod_redis/mod_redis.c
+++ b/src/mod/applications/mod_redis/mod_redis.c
@@ -89,7 +89,7 @@ SWITCH_LIMIT_INCR(limit_incr_redis)
 	}
 	
 	/* Get the keys for redis server */
-	uuid_rediskey = switch_core_session_sprintf(session,"%s_%s_%s", switch_core_get_variable("hostname"), realm, resource);
+	uuid_rediskey = switch_core_session_sprintf(session,"%s_%s_%s", switch_core_get_hostname(), realm, resource);
 	rediskey = switch_core_session_sprintf(session, "%s_%s", realm, resource);
 
 	if ((pvt = switch_channel_get_private(channel, "limit_redis"))) {
@@ -179,7 +179,7 @@ SWITCH_LIMIT_RELEASE(limit_release_redis)
 				switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Couldn't decrement value corresponding to %s\n", (char *)p_key);
 				switch_goto_status(SWITCH_STATUS_FALSE, end);
 			}
-	   		p_uuid_key = switch_core_session_sprintf(session, "%s_%s", switch_core_get_variable("hostname"), (char *)p_key);
+	   		p_uuid_key = switch_core_session_sprintf(session, "%s_%s", switch_core_get_hostname(), (char *)p_key);
 			if (credis_decr(redis,p_uuid_key,&uuid_val) != 0) {
 				switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Couldn't decrement value corresponding to %s\n", p_uuid_key);
 				switch_goto_status(SWITCH_STATUS_FALSE, end);
@@ -193,7 +193,7 @@ SWITCH_LIMIT_RELEASE(limit_release_redis)
 	
 	} else {	
 	   	rediskey = switch_core_session_sprintf(session, "%s_%s", realm, resource);
-		uuid_rediskey = switch_core_session_sprintf(session, "%s_%s_%s", switch_core_get_variable("hostname"), realm, resource);
+		uuid_rediskey = switch_core_session_sprintf(session, "%s_%s_%s", switch_core_get_hostname(), realm, resource);
 		switch_core_hash_delete(pvt->hash, (const char *) rediskey);
 
 		if (credis_decr(redis, rediskey, &val) != 0) {
@@ -249,13 +249,13 @@ SWITCH_LIMIT_RESET(limit_reset_redis)
 {
 	REDIS redis;
 	if (redis_factory(&redis) == SWITCH_STATUS_SUCCESS) {
-		char *rediskey = switch_mprintf("%s_*", switch_core_get_variable("hostname"));
+		char *rediskey = switch_mprintf("%s_*", switch_core_get_hostname());
 		int dec = 0, val = 0, keyc;
 		char *uuids[2000];
 	
 		if ((keyc = credis_keys(redis, rediskey, uuids, switch_arraylen(uuids))) > 0) {
 			int i = 0;
-			int hostnamelen = strlen(switch_core_get_variable("hostname"))+1;
+			int hostnamelen = strlen(switch_core_get_hostname())+1;
 			
 			for (i = 0; i < keyc && uuids[i]; i++){
 				const char *key = uuids[i] + hostnamelen;
diff --git a/src/mod/applications/mod_voicemail/mod_voicemail.c b/src/mod/applications/mod_voicemail/mod_voicemail.c
index 76870f7..80b011e 100644
--- a/src/mod/applications/mod_voicemail/mod_voicemail.c
+++ b/src/mod/applications/mod_voicemail/mod_voicemail.c
@@ -2734,6 +2734,7 @@ static switch_status_t voicemail_inject(const char *data, switch_core_session_t
 	switch_memory_pool_t *pool = NULL;
 	char *forwarded_by = NULL;
 	char *read_flags = NORMAL_FLAG_STRING;
+	char *dup_domain = NULL;
 	
 	if (zstr(data)) {
 		status = SWITCH_STATUS_FALSE;
@@ -2781,7 +2782,9 @@ static switch_status_t voicemail_inject(const char *data, switch_core_session_t
 	}
 
 	if (zstr(domain)) {
-		domain = switch_core_get_variable("domain");
+		if ((dup_domain = switch_core_get_variable_dup("domain"))) {
+			domain = dup_domain;
+		}
 		profile_name = domain;
 	}
 
@@ -2915,6 +2918,7 @@ static switch_status_t voicemail_inject(const char *data, switch_core_session_t
   end:
 
 	switch_safe_free(dup);
+	switch_safe_free(dup_domain);
 
 	return status;
 }
diff --git a/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c b/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c
index 5869d14..43534da 100644
--- a/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c
+++ b/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c
@@ -313,7 +313,7 @@ static switch_call_cause_t sip_outgoing_channel(switch_core_session_t *session,
 	if (session) {
 		profile = switch_channel_get_variable(switch_core_session_get_channel(session), "sip_profile");
 	} else {
-		profile = switch_core_get_variable("sip_profile");
+		profile = switch_core_get_variable_pdup("sip_profile", switch_core_session_get_pool(session));
 	}
 	if (zstr(profile)) {
 		profile = "default";
diff --git a/src/mod/endpoints/mod_dingaling/mod_dingaling.c b/src/mod/endpoints/mod_dingaling/mod_dingaling.c
index 66f62b2..9fb1f39 100644
--- a/src/mod/endpoints/mod_dingaling/mod_dingaling.c
+++ b/src/mod/endpoints/mod_dingaling/mod_dingaling.c
@@ -2049,7 +2049,7 @@ static void set_profile_val(mdl_profile_t *profile, char *var, char *val)
 	} else if (!strcasecmp(var, "ext-rtp-ip")) {
 		char *ip = globals.guess_ip;
 		if (val && !strcasecmp(val, "auto-nat")) {
-			ip = globals.auto_nat ? switch_core_get_variable("nat_public_addr") : globals.guess_ip;
+			ip = globals.auto_nat ? switch_core_get_variable_pdup("nat_public_addr", module_pool) : globals.guess_ip;
 		} else if (val && !strcasecmp(val, "auto")) {
 			globals.auto_nat = 0;
 			ip = globals.guess_ip;
@@ -2523,7 +2523,7 @@ static switch_status_t load_config(void)
 
 	memset(&globals, 0, sizeof(globals));
 	globals.running = 1;
-	globals.auto_nat = (switch_core_get_variable("nat_type") ? 1 : 0);
+	globals.auto_nat = (switch_nat_get_type() ? 1 : 0);
 
 	switch_find_local_ip(globals.guess_ip, sizeof(globals.guess_ip), NULL, AF_INET);
 
diff --git a/src/mod/endpoints/mod_khomp/src/khomp_pvt.cpp b/src/mod/endpoints/mod_khomp/src/khomp_pvt.cpp
index 1b126eb..15009f2 100644
--- a/src/mod/endpoints/mod_khomp/src/khomp_pvt.cpp
+++ b/src/mod/endpoints/mod_khomp/src/khomp_pvt.cpp
@@ -1625,9 +1625,10 @@ bool Board::KhompPvt::setCollectCall()
     DBG(FUNC, PVT_FMT(_target, "option drop collect call is '%s'") % (Opt::_options._drop_collect_call() ? "yes" : "no"));
 
     // get global filter configuration value
-    tmp_var = switch_core_get_variable("KDropCollectCall");
+    tmp_var = switch_core_get_variable_dup("KDropCollectCall");
     confvalues.push_back(getTriStateValue(tmp_var));
     DBG(FUNC, PVT_FMT(_target, "global KDropCollectCall was '%s'") % (tmp_var ? tmp_var : "(empty)"));
+	switch_safe_free(tmp_var);
 
     try 
     {
diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c
index 8bceb3b..c78aac7 100644
--- a/src/mod/endpoints/mod_sofia/mod_sofia.c
+++ b/src/mod/endpoints/mod_sofia/mod_sofia.c
@@ -3501,7 +3501,7 @@ SWITCH_STANDARD_API(sofia_contact_function)
 	}
 
 	if (zstr(domain)) {
-		domain = switch_core_get_variable("domain");
+		domain = switch_core_get_variable_pdup("domain", switch_core_session_get_pool(session));
 	}
 
 	if (!user) goto end;
@@ -4776,7 +4776,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
 	mod_sofia_globals.running = 1;
 	switch_mutex_unlock(mod_sofia_globals.mutex);
 
-	mod_sofia_globals.auto_nat = (switch_core_get_variable("nat_type") ? 1 : 0);
+	mod_sofia_globals.auto_nat = (switch_nat_get_type() ? 1 : 0);
 
 	switch_queue_create(&mod_sofia_globals.presence_queue, SOFIA_QUEUE_SIZE, mod_sofia_globals.pool);
 	switch_queue_create(&mod_sofia_globals.mwi_queue, SOFIA_QUEUE_SIZE, mod_sofia_globals.pool);
diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c
index 47f94b1..825d1bf 100644
--- a/src/mod/endpoints/mod_sofia/sofia.c
+++ b/src/mod/endpoints/mod_sofia/sofia.c
@@ -1459,7 +1459,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
 
 	supported = switch_core_sprintf(profile->pool, "%s%sprecondition, path, replaces", use_100rel ? "100rel, " : "", use_timer ? "timer, " : "");
 
-	if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && switch_core_get_variable("nat_type")) {
+	if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && switch_nat_get_type()) {
 		if (switch_nat_add_mapping(profile->sip_port, SWITCH_NAT_UDP, NULL, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created UDP nat mapping for %s port %d\n", profile->name, profile->sip_port);
 		}
@@ -1676,7 +1676,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
 		switch_event_fire(&s_event);
 	}
 
-	if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && switch_core_get_variable("nat_type")) {
+	if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && switch_nat_get_type()) {
 		if (switch_nat_del_mapping(profile->sip_port, SWITCH_NAT_UDP) == SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleted UDP nat mapping for %s port %d\n", profile->name, profile->sip_port);
 		}
@@ -3741,9 +3741,9 @@ switch_status_t config_sofia(int reload, char *profile_name)
 				if (!profile->rtpip[0]) {
 					profile->rtpip[profile->rtpip_index++] = switch_core_strdup(profile->pool, mod_sofia_globals.guess_ip);
 				}
-
-				if (switch_core_get_variable("nat_type")) {
-					const char *ip = switch_core_get_variable("nat_public_addr");
+				
+				if (switch_nat_get_type()) {
+					char *ip = switch_core_get_variable_dup("nat_public_addr");
 					if (ip && !strchr(profile->sipip, ':')) {
 						if (!profile->extrtpip) {
 							profile->extrtpip = switch_core_strdup(profile->pool, ip);
@@ -3754,6 +3754,7 @@ switch_status_t config_sofia(int reload, char *profile_name)
 						sofia_set_pflag(profile, PFLAG_AUTO_NAT);
 						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "NAT detected setting external ip to %s\n", ip);
 					}
+					switch_safe_free(ip);
 				}
 
 				if (profile->nonce_ttl < 60) {
diff --git a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
index f3a2c92..1462e4e 100644
--- a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
+++ b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
@@ -2642,7 +2642,7 @@ static int config(void)
 				} else if (!strcmp(var, "debug")) {
 					globals.debug = atoi(val);
 				} else if (!strcmp(var, "nat-map")) {
-					if (switch_true(val) && switch_core_get_variable("nat_type")) {
+					if (switch_true(val) && switch_nat_get_type()) {
 						prefs.nat_map = 1;
 					}
 				} else if (!strcmp(var, "listen-port")) {
@@ -2795,7 +2795,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_socket_runtime)
 
 	close_socket(&listen_list.sock);
 
-	if (prefs.nat_map && switch_core_get_variable("nat_type")) {
+	if (prefs.nat_map && switch_nat_get_type()) {
 		switch_nat_del_mapping(prefs.port, SWITCH_NAT_TCP);
 	}
 
diff --git a/src/mod/formats/mod_file_string/mod_file_string.c b/src/mod/formats/mod_file_string/mod_file_string.c
index ca86cbd..7e36c72 100644
--- a/src/mod/formats/mod_file_string/mod_file_string.c
+++ b/src/mod/formats/mod_file_string/mod_file_string.c
@@ -77,7 +77,7 @@ static int next_file(switch_file_handle_t *handle)
 
 
 	if (!prefix) {
-		if (!(prefix = switch_core_get_variable("sound_prefix"))) {
+		if (!(prefix = switch_core_get_variable_pdup("sound_prefix", handle->memory_pool))) {
 			prefix = SWITCH_GLOBAL_dirs.sounds_dir;
 		}
 	}
diff --git a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
index 9eb2636..1d6ee8d 100644
--- a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
+++ b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
@@ -3378,8 +3378,9 @@ static JSBool js_global_get(JSContext * cx, JSObject * obj, uintN argc, jsval *
 
 	if (argc > 0) {
 		var_name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
-		val = switch_core_get_variable(var_name);
+		val = switch_core_get_variable_dup(var_name);
 		*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, val));
+		free(val);
 		return JS_TRUE;
 	}
 
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 468190d..9e61312 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
@@ -322,6 +322,7 @@ static abyss_bool http_directory_auth(TSession * r, char *domain_name)
 	int at = 0;
 	char *dp;
 	abyss_bool rval = FALSE;
+	char *dup_domain = NULL;
 
 	p = RequestHeaderValue(r, "authorization");
 
@@ -354,7 +355,9 @@ static abyss_bool http_directory_auth(TSession * r, char *domain_name)
 						if (globals.default_domain) {
 							domain_name = globals.default_domain;
 						} else {
-							domain_name = switch_core_get_variable("domain");
+							if ((dup_domain = switch_core_get_variable_dup("domain"))) {
+								domain_name = dup_domain;
+							}
 						}
 					}
 				}
@@ -465,6 +468,7 @@ static abyss_bool http_directory_auth(TSession * r, char *domain_name)
 	switch_safe_free(mypass1);
 	switch_safe_free(mypass2);
 	switch_safe_free(box);
+	switch_safe_free(dup_domain);
 
 	return rval;
 }
diff --git a/src/switch_channel.c b/src/switch_channel.c
index 70b1879..f750496 100644
--- a/src/switch_channel.c
+++ b/src/switch_channel.c
@@ -672,7 +672,7 @@ SWITCH_DECLARE(const char *) switch_channel_get_hold_music_partner(switch_channe
 
 SWITCH_DECLARE(const char *) switch_channel_get_variable_dup(switch_channel_t *channel, const char *varname, switch_bool_t dup)
 {
-	const char *v = NULL, *r = NULL;
+	const char *v = NULL, *r = NULL, *vdup = NULL;
 	switch_assert(channel != NULL);
 
 	switch_mutex_lock(channel->profile_mutex);
@@ -690,13 +690,16 @@ SWITCH_DECLARE(const char *) switch_channel_get_variable_dup(switch_channel_t *c
 		}
 
 		if (!cp || !(v = switch_caller_get_field_by_name(cp, varname))) {
-			v = switch_core_get_variable(varname);
+			if ((vdup = switch_core_get_variable_pdup(varname, switch_core_session_get_pool(channel->session)))) {
+				v = vdup;
+			}
 		}
 	}
 
-	if (dup) {
-		if (v)
+	if (dup && v != vdup) {
+		if (v) {
 			r = switch_core_session_strdup(channel->session, v);
+		}
 	} else {
 		r = v;
 	}
diff --git a/src/switch_console.c b/src/switch_console.c
index 41bbb91..c5d601b 100644
--- a/src/switch_console.c
+++ b/src/switch_console.c
@@ -643,9 +643,9 @@ SWITCH_DECLARE_NONSTD(switch_status_t) switch_console_list_uuid(const char *line
 
 	if (!zstr(cursor)) {
 		sql = switch_mprintf("select distinct uuid from channels where uuid like '%q%%' and hostname='%q' order by uuid",
-							 cursor, switch_core_get_variable("hostname"));
+							 cursor, switch_core_get_hostname());
 	} else {
-		sql = switch_mprintf("select distinct uuid from channels where hostname='%q' order by uuid", switch_core_get_variable("hostname"));
+		sql = switch_mprintf("select distinct uuid from channels where hostname='%q' order by uuid", switch_core_get_hostname());
 	}
 
 	switch_cache_db_execute_sql_callback(db, sql, uuid_callback, &h, &errmsg);
@@ -764,7 +764,7 @@ SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const ch
 
 	if (h.words == 0) {
 		sql = switch_mprintf("select distinct name from interfaces where type='api' and name like '%q%%' and hostname='%q' order by name",
-							 buf, switch_core_get_variable("hostname"));
+							 buf, switch_core_get_hostname());
 	}
 
 	if (sql) {
@@ -792,7 +792,7 @@ SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const ch
 
 		if (h.words == 0) {
 			stream.write_function(&stream, "select distinct a1 from complete where " "a1 not in (select name from interfaces where hostname='%s') %s ",
-								  switch_core_get_variable("hostname"), argc ? "and" : "");
+								  switch_core_get_hostname(), argc ? "and" : "");
 		} else {
 			if (db->type == SCDB_TYPE_CORE_DB) {
 				stream.write_function(&stream, "select distinct a%d,'%q','%q' from complete where ", h.words + 1, switch_str_nil(dup), switch_str_nil(lp));
@@ -821,7 +821,7 @@ SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const ch
 			}
 		}
 
-		stream.write_function(&stream, " and hostname='%s' order by a%d", switch_core_get_variable("hostname"), h.words + 1);
+		stream.write_function(&stream, " and hostname='%s' order by a%d", switch_core_get_hostname(), h.words + 1);
 		
 		switch_cache_db_execute_sql_callback(db, stream.data, comp_callback, &h, &errmsg);
 
@@ -1794,7 +1794,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string)
 						}
 					}
 				}
-				mystream.write_function(&mystream, " '%s')", switch_core_get_variable("hostname"));
+				mystream.write_function(&mystream, " '%s')", switch_core_get_hostname());
 				switch_cache_db_persistant_execute(db, mystream.data, 5);
 				status = SWITCH_STATUS_SUCCESS;
 			} else if (!strcasecmp(argv[0], "add")) {
@@ -1810,7 +1810,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string)
 						}
 					}
 				}
-				mystream.write_function(&mystream, " '%s')", switch_core_get_variable("hostname"));
+				mystream.write_function(&mystream, " '%s')", switch_core_get_hostname());
 
 				switch_cache_db_persistant_execute(db, mystream.data, 5);
 				status = SWITCH_STATUS_SUCCESS;
@@ -1827,7 +1827,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string)
 							mystream.write_function(&mystream, "a%d = '%w'%w", x + 1, switch_str_nil(argv[x + 1]), x == argc - 2 ? "" : " and ");
 						}
 					}
-					mystream.write_function(&mystream, " and hostname='%s'", switch_core_get_variable("hostname"));
+					mystream.write_function(&mystream, " and hostname='%s'", switch_core_get_hostname());
 					switch_cache_db_persistant_execute(db, mystream.data, 1);
 				}
 				status = SWITCH_STATUS_SUCCESS;
@@ -1863,38 +1863,38 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_alias(const char *string)
 			}
 			
 			if (!strcasecmp(argv[0], "stickyadd") && argc == 3) {
-				sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_variable("hostname"));
+				sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_hostname());
 				switch_cache_db_persistant_execute(db, sql, 5);
 				switch_safe_free(sql);
 				if (db->type == SCDB_TYPE_CORE_DB) {
 					sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (1, '%q','%q','%q')",
-										 argv[1], argv[2], switch_core_get_variable("hostname"));
+										 argv[1], argv[2], switch_core_get_hostname());
 				} else {
 					sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (1, '%w','%w','%w')",
-										 argv[1], argv[2], switch_core_get_variable("hostname"));
+										 argv[1], argv[2], switch_core_get_hostname());
 				}
 				switch_cache_db_persistant_execute(db, sql, 5);
 				status = SWITCH_STATUS_SUCCESS;
 			} else if (!strcasecmp(argv[0], "add") && argc == 3) {
-				sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_variable("hostname"));
+				sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_hostname());
 				switch_cache_db_persistant_execute(db, sql, 5);
 				switch_safe_free(sql);
 				if (db->type == SCDB_TYPE_CORE_DB) {
 					sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (0, '%q','%q','%q')",
-										 argv[1], argv[2], switch_core_get_variable("hostname"));
+										 argv[1], argv[2], switch_core_get_hostname());
 				} else {
 					sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (0, '%w','%w','%w')",
-										 argv[1], argv[2], switch_core_get_variable("hostname"));
+										 argv[1], argv[2], switch_core_get_hostname());
 				}
 				switch_cache_db_persistant_execute(db, sql, 5);
 				status = SWITCH_STATUS_SUCCESS;
 			} else if (!strcasecmp(argv[0], "del") && argc == 2) {
 				char *what = argv[1];
 				if (!strcasecmp(what, "*")) {
-					sql = switch_mprintf("delete from aliases where hostname='%q'", switch_core_get_variable("hostname"));
+					sql = switch_mprintf("delete from aliases where hostname='%q'", switch_core_get_hostname());
 					switch_cache_db_persistant_execute(db, sql, 1);
 				} else {
-					sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_variable("hostname"));
+					sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_hostname());
 					switch_cache_db_persistant_execute(db, sql, 5);
 				}
 				status = SWITCH_STATUS_SUCCESS;
diff --git a/src/switch_core.c b/src/switch_core.c
index 43fb36d..8754305 100644
--- a/src/switch_core.c
+++ b/src/switch_core.c
@@ -261,6 +261,11 @@ SWITCH_DECLARE(void) switch_core_dump_variables(switch_stream_handle_t *stream)
 	switch_mutex_unlock(runtime.global_mutex);
 }
 
+SWITCH_DECLARE(const char *) switch_core_get_hostname(void)
+{
+	return runtime.hostname;
+}
+
 SWITCH_DECLARE(char *) switch_core_get_variable(const char *varname)
 {
 	char *val;
@@ -270,6 +275,32 @@ SWITCH_DECLARE(char *) switch_core_get_variable(const char *varname)
 	return val;
 }
 
+SWITCH_DECLARE(char *) switch_core_get_variable_dup(const char *varname)
+{
+	char *val = NULL, *v;
+
+	switch_mutex_lock(runtime.global_var_mutex);
+	if ((v = (char *) switch_event_get_header(runtime.global_vars, varname))) {
+		val = strdup(v);
+	}
+	switch_mutex_unlock(runtime.global_var_mutex);
+
+	return val;
+}
+
+SWITCH_DECLARE(char *) switch_core_get_variable_pdup(const char *varname, switch_memory_pool_t *pool)
+{
+	char *val = NULL, *v;
+
+	switch_mutex_lock(runtime.global_var_mutex);
+	if ((v = (char *) switch_event_get_header(runtime.global_vars, varname))) {
+		val = switch_core_strdup(pool, v);
+	}
+	switch_mutex_unlock(runtime.global_var_mutex);
+
+	return val;
+}
+
 static void switch_core_unset_variables(void)
 {
 	switch_mutex_lock(runtime.global_var_mutex);
@@ -1202,12 +1233,18 @@ static void switch_core_set_serial(void)
 
 
 	if ((fd = open(path, O_RDONLY, 0)) < 0) {
-		char *ip = switch_core_get_variable("local_ip_v4");
+		char *ip = switch_core_get_variable_dup("local_ip_v4");
 		uint32_t ipi = 0;
 		switch_byte_t *byte;
 		int i = 0;
 
-		switch_inet_pton(AF_INET, ip, &ipi);
+		if (ip) {
+			switch_inet_pton(AF_INET, ip, &ipi);
+			free(ip);
+			ip = NULL;
+		}
+
+
 		byte = (switch_byte_t *) & ipi;
 
 		for (i = 0; i < 8; i += 2) {
@@ -1237,7 +1274,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
 	char guess_ip[256];
 	int mask = 0;
 	struct in_addr in;
-	char hostname[256] = "";
+
 
 	if (runtime.runlevel > 0) {
 		/* one per customer */
@@ -1310,8 +1347,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
 		runtime.console = stdout;
 	}
 
-	gethostname(hostname, sizeof(hostname));
-	switch_core_set_variable("hostname", hostname);
+	gethostname(runtime.hostname, sizeof(runtime.hostname));
+	switch_core_set_variable("hostname", runtime.hostname);
 
 	switch_find_local_ip(guess_ip, sizeof(guess_ip), &mask, AF_INET);
 	switch_core_set_variable("local_ip_v4", guess_ip);
diff --git a/src/switch_core_file.c b/src/switch_core_file.c
index 19f2354..fc7d223 100644
--- a/src/switch_core_file.c
+++ b/src/switch_core_file.c
@@ -102,7 +102,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file,
 			}
 
 			if (!spool_path) {
-				spool_path = switch_core_get_variable(SWITCH_AUDIO_SPOOL_PATH_VARIABLE);
+				spool_path = switch_core_get_variable_pdup(SWITCH_AUDIO_SPOOL_PATH_VARIABLE, fh->memory_pool);
 			}
 
 			file_path = fh->file_path;
diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c
index 2db2a0d..73890a1 100644
--- a/src/switch_core_sqldb.c
+++ b/src/switch_core_sqldb.c
@@ -1134,7 +1134,7 @@ static void core_event_handler(switch_event_t *event)
 				new_sql() = switch_mprintf("insert into tasks values(%q,'%q','%q',%q, '%q')",
 										   id,
 										   switch_event_get_header_nil(event, "task-desc"),
-										   switch_event_get_header_nil(event, "task-group"), manager ? manager : "0", switch_core_get_variable("hostname")
+										   switch_event_get_header_nil(event, "task-group"), manager ? manager : "0", switch_core_get_hostname()
 										   );
 			}
 		}
@@ -1142,7 +1142,7 @@ static void core_event_handler(switch_event_t *event)
 	case SWITCH_EVENT_DEL_SCHEDULE:
 	case SWITCH_EVENT_EXE_SCHEDULE:
 		new_sql() = switch_mprintf("delete from tasks where task_id=%q and hostname='%q'",
-								   switch_event_get_header_nil(event, "task-id"), switch_core_get_variable("hostname"));
+								   switch_event_get_header_nil(event, "task-id"), switch_core_get_hostname());
 		break;
 	case SWITCH_EVENT_RE_SCHEDULE:
 		{
@@ -1153,7 +1153,7 @@ static void core_event_handler(switch_event_t *event)
 				new_sql() = switch_mprintf("update tasks set task_desc='%q',task_group='%q', task_sql_manager=%q where task_id=%q and hostname='%q'",
 										   switch_event_get_header_nil(event, "task-desc"),
 										   switch_event_get_header_nil(event, "task-group"), manager ? manager : "0", id,
-										   switch_core_get_variable("hostname"));
+										   switch_core_get_hostname());
 			}
 		}
 		break;
@@ -1163,10 +1163,10 @@ static void core_event_handler(switch_event_t *event)
 			
 			if (uuid) {
 				new_sql() = switch_mprintf("delete from channels where uuid='%q' and hostname='%q'",
-										   uuid, switch_core_get_variable("hostname"));
+										   uuid, switch_core_get_hostname());
 
 				new_sql() = switch_mprintf("delete from calls where (caller_uuid='%q' or callee_uuid='%q') and hostname='%q'",
-										   uuid, uuid, switch_core_get_variable("hostname"));
+										   uuid, uuid, switch_core_get_hostname());
 
 			}
 		}
@@ -1178,12 +1178,12 @@ static void core_event_handler(switch_event_t *event)
 									   "update calls set callee_uuid='%q' where callee_uuid='%q' and hostname='%q'",
 									   switch_event_get_header_nil(event, "unique-id"),
 									   switch_event_get_header_nil(event, "old-unique-id"),
-									   switch_core_get_variable("hostname"),
+									   switch_core_get_hostname(),
 									   switch_event_get_header_nil(event, "unique-id"),
 									   switch_event_get_header_nil(event, "old-unique-id"),
-									   switch_core_get_variable("hostname"),
+									   switch_core_get_hostname(),
 									   switch_event_get_header_nil(event, "unique-id"),
-									   switch_event_get_header_nil(event, "old-unique-id"), switch_core_get_variable("hostname")
+									   switch_event_get_header_nil(event, "old-unique-id"), switch_core_get_hostname()
 									   );
 			break;
 		}
@@ -1198,7 +1198,7 @@ static void core_event_handler(switch_event_t *event)
 								   switch_event_get_header_nil(event, "channel-state"),
 								   switch_event_get_header_nil(event, "channel-call-state"),
 								   switch_event_get_header_nil(event, "caller-dialplan"),
-								   switch_event_get_header_nil(event, "caller-context"), switch_core_get_variable("hostname")
+								   switch_event_get_header_nil(event, "caller-context"), switch_core_get_hostname()
 								   );
 		break;
 	case SWITCH_EVENT_CODEC:
@@ -1211,7 +1211,7 @@ static void core_event_handler(switch_event_t *event)
 			 switch_event_get_header_nil(event, "channel-write-codec-name"),
 			 switch_event_get_header_nil(event, "channel-write-codec-rate"),
 			 switch_event_get_header_nil(event, "channel-write-codec-bit-rate"),
-			 switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
+			 switch_event_get_header_nil(event, "unique-id"), switch_core_get_hostname());
 		break;
 	case SWITCH_EVENT_CHANNEL_HOLD:
 	case SWITCH_EVENT_CHANNEL_UNHOLD:
@@ -1223,7 +1223,7 @@ static void core_event_handler(switch_event_t *event)
 								   switch_event_get_header_nil(event, "application-data"),
 								   switch_event_get_header_nil(event, "channel-presence-id"),
 								   switch_event_get_header_nil(event, "channel-presence-data"),
-								   switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname")
+								   switch_event_get_header_nil(event, "unique-id"), switch_core_get_hostname()
 								   );
 
 	}
@@ -1238,7 +1238,7 @@ static void core_event_handler(switch_event_t *event)
 										   switch_event_get_header_nil(event, "channel-presence-data"),
 										   switch_event_get_header_nil(event, "channel-call-uuid"),
 										   extra_cols,
-										   switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
+										   switch_event_get_header_nil(event, "unique-id"), switch_core_get_hostname());
 				free(extra_cols);
 			} else {
 				new_sql() = switch_mprintf("update channels set "
@@ -1246,7 +1246,7 @@ static void core_event_handler(switch_event_t *event)
 										   switch_event_get_header_nil(event, "channel-presence-id"),
 										   switch_event_get_header_nil(event, "channel-presence-data"),
 										   switch_event_get_header_nil(event, "channel-call-uuid"),
-										   switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
+										   switch_event_get_header_nil(event, "unique-id"), switch_core_get_hostname());
 			}
 
 		}
@@ -1281,7 +1281,7 @@ static void core_event_handler(switch_event_t *event)
 										   switch_str_nil(name),
 										   switch_str_nil(number),
 										   switch_event_get_header_nil(event, "direction"),
-										   switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
+										   switch_event_get_header_nil(event, "unique-id"), switch_core_get_hostname());
 
 				name = switch_event_get_header(event, "callee-name");
 				number = switch_event_get_header(event, "callee-number");
@@ -1298,7 +1298,7 @@ static void core_event_handler(switch_event_t *event)
 		{
 			new_sql() = switch_mprintf("update channels set callstate='%q' where uuid='%q' and hostname='%q'",
 									   switch_event_get_header_nil(event, "channel-call-state"),
-									   switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
+									   switch_event_get_header_nil(event, "unique-id"), switch_core_get_hostname());
 
 		}
 		break;
@@ -1330,7 +1330,7 @@ static void core_event_handler(switch_event_t *event)
 											   switch_event_get_header_nil(event, "channel-presence-id"),
 											   switch_event_get_header_nil(event, "channel-presence-data"),
 											   extra_cols,
-											   switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
+											   switch_event_get_header_nil(event, "unique-id"), switch_core_get_hostname());
 					free(extra_cols);
 				} else {
 					new_sql() = switch_mprintf("update channels set state='%s',cid_name='%q',cid_num='%q',"
@@ -1345,13 +1345,13 @@ static void core_event_handler(switch_event_t *event)
 											   switch_event_get_header_nil(event, "caller-context"),
 											   switch_event_get_header_nil(event, "channel-presence-id"),
 											   switch_event_get_header_nil(event, "channel-presence-data"),
-											   switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
+											   switch_event_get_header_nil(event, "unique-id"), switch_core_get_hostname());
 				}
 				break;
 			default:
 				new_sql() = switch_mprintf("update channels set state='%s' where uuid='%s' and hostname='%q'",
 										   switch_event_get_header_nil(event, "channel-state"),
-										   switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
+										   switch_event_get_header_nil(event, "unique-id"), switch_core_get_hostname());
 				break;
 			}
 
@@ -1377,7 +1377,7 @@ static void core_event_handler(switch_event_t *event)
 
 			new_sql() = switch_mprintf("update channels set call_uuid='%q' where uuid='%s' and hostname='%q'",
 									   switch_event_get_header_nil(event, "channel-call-uuid"),
-									   switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
+									   switch_event_get_header_nil(event, "unique-id"), switch_core_get_hostname());
 
 			if (runtime.odbc_dbtype == DBTYPE_DEFAULT) {
 				func_name = "function";
@@ -1404,7 +1404,7 @@ static void core_event_handler(switch_event_t *event)
 									   callee_cid_num,
 									   switch_event_get_header_nil(event, "Other-Leg-destination-number"),
 									   switch_event_get_header_nil(event, "Other-Leg-channel-name"),
-									   switch_event_get_header_nil(event, "Other-Leg-unique-id"), switch_core_get_variable("hostname")
+									   switch_event_get_header_nil(event, "Other-Leg-unique-id"), switch_core_get_hostname()
 									   );
 		}
 		break;
@@ -1413,14 +1413,14 @@ static void core_event_handler(switch_event_t *event)
 			char *uuid = switch_event_get_header_nil(event, "caller-unique-id");
 
 			new_sql() = switch_mprintf("delete from calls where (caller_uuid='%q' or callee_uuid='%q') and hostname='%q'",
-									   uuid, uuid, switch_core_get_variable("hostname"));
+									   uuid, uuid, switch_core_get_hostname());
 			break;
 		}
 	case SWITCH_EVENT_SHUTDOWN:
 		new_sql() = switch_mprintf("delete from channels where hostname='%q';"
 								   "delete from interfaces where hostname='%q';"
 								   "delete from calls where hostname='%q'",
-								   switch_core_get_variable("hostname"), switch_core_get_variable("hostname"), switch_core_get_variable("hostname")
+								   switch_core_get_hostname(), switch_core_get_hostname(), switch_core_get_hostname()
 								   );
 		break;
 	case SWITCH_EVENT_LOG:
@@ -1438,7 +1438,7 @@ static void core_event_handler(switch_event_t *event)
 					switch_mprintf
 					("insert into interfaces (type,name,description,syntax,ikey,filename,hostname) values('%q','%q','%q','%q','%q','%q','%q')", type, name,
 					 switch_str_nil(description), switch_str_nil(syntax), switch_str_nil(key), switch_str_nil(filename),
-					 switch_core_get_variable("hostname")
+					 switch_core_get_hostname()
 					 );
 			}
 			break;
@@ -1449,7 +1449,7 @@ static void core_event_handler(switch_event_t *event)
 			const char *name = switch_event_get_header_nil(event, "name");
 			if (!zstr(type) && !zstr(name)) {
 				new_sql() = switch_mprintf("delete from interfaces where type='%q' and name='%q' and hostname='%q'", type, name,
-										   switch_core_get_variable("hostname"));
+										   switch_core_get_hostname());
 			}
 			break;
 		}
@@ -1461,7 +1461,7 @@ static void core_event_handler(switch_event_t *event)
 				break;
 			}
 			new_sql() = switch_mprintf("update channels set secure='%s' where uuid='%s' and hostname='%q'",
-									   type, switch_event_get_header_nil(event, "caller-unique-id"), switch_core_get_variable("hostname")
+									   type, switch_event_get_header_nil(event, "caller-unique-id"), switch_core_get_hostname()
 									   );
 			break;
 		}
@@ -1472,12 +1472,12 @@ static void core_event_handler(switch_event_t *event)
 			if (!strcmp("add", op)) {
 				new_sql() = switch_mprintf("insert into nat (port, proto, sticky, hostname) values (%s, %s, %d,'%q')",
 										   switch_event_get_header_nil(event, "port"),
-										   switch_event_get_header_nil(event, "proto"), sticky, switch_core_get_variable("hostname")
+										   switch_event_get_header_nil(event, "proto"), sticky, switch_core_get_hostname()
 										   );
 			} else if (!strcmp("del", op)) {
 				new_sql() = switch_mprintf("delete from nat where port=%s and proto=%s and hostname='%q'",
 										   switch_event_get_header_nil(event, "port"),
-										   switch_event_get_header_nil(event, "proto"), switch_core_get_variable("hostname"));
+										   switch_event_get_header_nil(event, "proto"), switch_core_get_hostname());
 			} else if (!strcmp("status", op)) {
 				/* call show nat api */
 			} else if (!strcmp("status_response", op)) {
@@ -1664,7 +1664,7 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
 			char sql[512] = "";
 			char *tables[] = { "channels", "calls", "interfaces", "tasks", NULL };
 			int i;
-			const char *hostname = switch_core_get_variable("hostname");
+			const char *hostname = switch_core_get_hostname();
 
 			for (i = 0; tables[i]; i++) {
 				switch_snprintf(sql, sizeof(sql), "delete from %s where hostname='%s'", tables[i], hostname);
diff --git a/src/switch_event.c b/src/switch_event.c
index 003fc82..3e12ea1 100644
--- a/src/switch_event.c
+++ b/src/switch_event.c
@@ -1673,6 +1673,7 @@ SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const
 					int offset = 0;
 					int ooffset = 0;
 					char *ptr;
+					char *gvar = NULL;
 
 					if ((expanded = switch_event_expand_headers(event, (char *) vname)) == vname) {
 						expanded = NULL;
@@ -1689,7 +1690,9 @@ SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const
 					}
 
 					if (!(sub_val = switch_event_get_header(event, vname))) {
-						sub_val = switch_core_get_variable(vname);
+						if ((gvar = switch_core_get_variable_dup(vname))) {
+							sub_val = gvar;
+						}
 					}
 
 					if (offset || ooffset) {
@@ -1710,6 +1713,7 @@ SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const
 						}
 					}
 
+					switch_safe_free(gvar);
 					switch_safe_free(expanded);
 				} else {
 					switch_stream_handle_t stream = { 0 };
diff --git a/src/switch_nat.c b/src/switch_nat.c
index 536baee..85b0247 100644
--- a/src/switch_nat.c
+++ b/src/switch_nat.c
@@ -45,6 +45,7 @@
 
 typedef struct {
 	switch_nat_type_t nat_type;
+	char nat_type_str[5];
 	struct UPNPUrls urls;
 	struct IGDdatas data;
 	char *descURL;
@@ -420,6 +421,7 @@ SWITCH_DECLARE(void) switch_nat_init(switch_memory_pool_t *pool)
 		switch_core_set_variable("nat_public_addr", nat_globals.pub_addr);
 		switch_core_set_variable("nat_private_addr", nat_globals.pvt_addr);
 		switch_core_set_variable("nat_type", nat_globals.nat_type == SWITCH_NAT_TYPE_PMP ? "pmp" : "upnp");
+		strncpy(nat_globals.nat_type_str, nat_globals.nat_type == SWITCH_NAT_TYPE_PMP ? "pmp" : "upnp", sizeof(nat_globals.nat_type_str) - 1);
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "NAT detected type: %s, ExtIP: '%s'\n",
 						  nat_globals.nat_type == SWITCH_NAT_TYPE_PMP ? "pmp" : "upnp", nat_globals.pub_addr);
 
@@ -564,6 +566,11 @@ static switch_status_t switch_nat_del_mapping_upnp(switch_port_t port, switch_na
 	return status;
 }
 
+SWITCH_DECLARE(const char *) switch_nat_get_type(void)
+{
+	return nat_globals.nat_type_str;
+}
+
 SWITCH_DECLARE(switch_status_t) switch_nat_add_mapping_internal(switch_port_t port, switch_nat_ip_proto_t proto, switch_port_t * external_port,
 																switch_bool_t sticky, switch_bool_t publish)
 {
diff --git a/src/switch_rtp.c b/src/switch_rtp.c
index 4acadfe..e8d7558 100644
--- a/src/switch_rtp.c
+++ b/src/switch_rtp.c
@@ -791,8 +791,8 @@ static void zrtp_logger(int level, const char *data, int len, int offset)
 SWITCH_DECLARE(void) switch_rtp_init(switch_memory_pool_t *pool)
 {
 #ifdef ENABLE_ZRTP
-	const char *zid_string = switch_core_get_variable("switch_serial");
-	const char *zrtp_enabled = switch_core_get_variable("zrtp_enabled");
+	const char *zid_string = switch_core_get_variable_pdup("switch_serial", pool);
+	const char *zrtp_enabled = switch_core_get_variable_pdup("zrtp_enabled", pool);
 	zrtp_config_t zrtp_config;
 	char zrtp_cache_path[256] = "";
 	zrtp_on = zrtp_enabled ? switch_true(zrtp_enabled) : 0;
diff --git a/src/switch_utils.c b/src/switch_utils.c
index 850b07f..eb5ed7f 100644
--- a/src/switch_utils.c
+++ b/src/switch_utils.c
@@ -1154,8 +1154,8 @@ SWITCH_DECLARE(switch_status_t) switch_find_local_ip(char *buf, int len, int *ma
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	char *base;
-	const char *force_local_ip_v4 = switch_core_get_variable("force_local_ip_v4");
-	const char *force_local_ip_v6 = switch_core_get_variable("force_local_ip_v6");
+	char *force_local_ip_v4 = switch_core_get_variable_dup("force_local_ip_v4");
+	char *force_local_ip_v6 = switch_core_get_variable_dup("force_local_ip_v6");
 
 #ifdef WIN32
 	SOCKET tmp_socket;
@@ -1176,14 +1176,20 @@ SWITCH_DECLARE(switch_status_t) switch_find_local_ip(char *buf, int len, int *ma
 	case AF_INET:
 		if (force_local_ip_v4) {
 			switch_copy_string(buf, force_local_ip_v4, len);
+			switch_safe_free(force_local_ip_v4);
+			switch_safe_free(force_local_ip_v6);
 			return SWITCH_STATUS_SUCCESS;
 		}
 	case AF_INET6:
 		if (force_local_ip_v6) {
 			switch_copy_string(buf, force_local_ip_v6, len);
+			switch_safe_free(force_local_ip_v4);
+			switch_safe_free(force_local_ip_v6);
 			return SWITCH_STATUS_SUCCESS;
 		}
 	default:
+		switch_safe_free(force_local_ip_v4);
+		switch_safe_free(force_local_ip_v6);
 		break;
 	}
 
diff --git a/src/switch_xml.c b/src/switch_xml.c
index 964a769..4c30d98 100644
--- a/src/switch_xml.c
+++ b/src/switch_xml.c
@@ -1208,11 +1208,12 @@ static char *expand_vars(char *buf, char *ebuf, switch_size_t elen, switch_size_
 				var = rp;
 				*e++ = '\0';
 				rp = e;
-				if ((val = switch_core_get_variable(var))) {
+				if ((val = switch_core_get_variable_dup(var))) {
 					char *p;
 					for (p = val; p && *p && wp <= ep; p++) {
 						*wp++ = *p;
 					}
+					free(val);
 				}
 				continue;
 			} else if (err) {

-----------------------------------------------------------------------

Summary of changes:
 src/include/private/switch_core_pvt.h              |    1 +
 src/include/switch_core.h                          |    3 +
 src/include/switch_nat.h                           |    2 +-
 src/mod/applications/mod_commands/mod_commands.c   |   29 +++++++---
 src/mod/applications/mod_dptools/mod_dptools.c     |   17 +++---
 src/mod/applications/mod_redis/mod_redis.c         |   10 ++--
 src/mod/applications/mod_voicemail/mod_voicemail.c |    6 ++-
 .../mod_dialplan_asterisk/mod_dialplan_asterisk.c  |    2 +-
 src/mod/endpoints/mod_dingaling/mod_dingaling.c    |    4 +-
 src/mod/endpoints/mod_khomp/src/khomp_pvt.cpp      |    3 +-
 src/mod/endpoints/mod_sofia/mod_sofia.c            |    4 +-
 src/mod/endpoints/mod_sofia/sofia.c                |   11 ++--
 .../mod_event_socket/mod_event_socket.c            |    4 +-
 src/mod/formats/mod_file_string/mod_file_string.c  |    2 +-
 .../languages/mod_spidermonkey/mod_spidermonkey.c  |    3 +-
 src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c          |    6 ++-
 src/switch_channel.c                               |   11 +++--
 src/switch_console.c                               |   32 ++++++------
 src/switch_core.c                                  |   47 +++++++++++++++--
 src/switch_core_file.c                             |    2 +-
 src/switch_core_sqldb.c                            |   56 ++++++++++----------
 src/switch_event.c                                 |    6 ++-
 src/switch_nat.c                                   |    7 +++
 src/switch_rtp.c                                   |    4 +-
 src/switch_utils.c                                 |   10 +++-
 src/switch_xml.c                                   |    3 +-
 26 files changed, 185 insertions(+), 100 deletions(-)


hooks/post-receive
-- 
FreeSWITCH Source



More information about the Freeswitch-trunk mailing list