[asterisk-commits] file: branch group/dns r433000 - /team/group/dns/res/res_resolver_unbound.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 16 13:13:50 CDT 2015


Author: file
Date: Mon Mar 16 13:13:48 2015
New Revision: 433000

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=433000
Log:
Reduce memory usage when no explicit nameservers are specified.

Modified:
    team/group/dns/res/res_resolver_unbound.c

Modified: team/group/dns/res/res_resolver_unbound.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns/res/res_resolver_unbound.c?view=diff&rev=433000&r1=432999&r2=433000
==============================================================================
--- team/group/dns/res/res_resolver_unbound.c (original)
+++ team/group/dns/res/res_resolver_unbound.c Mon Mar 16 13:13:48 2015
@@ -372,11 +372,6 @@
 		goto error;
 	}
 
-	cfg->global->nameservers = ast_str_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, 1);
-	if (!cfg->global->nameservers) {
-		goto error;
-	}
-
 	return cfg;
 error:
 	ao2_ref(cfg, -1);
@@ -386,8 +381,6 @@
 static int unbound_config_preapply(struct unbound_config *cfg)
 {
 	int res = 0;
-	struct ao2_iterator it_nameservers;
-	const char *nameserver;
 
 	cfg->global->state = ao2_alloc_options(sizeof(*cfg->global->state), unbound_config_state_destructor,
 		AO2_ALLOC_OPT_LOCK_NOLOCK);
@@ -416,18 +409,23 @@
 		return -1;
 	}
 
-	it_nameservers = ao2_iterator_init(cfg->global->nameservers, 0);
-	while ((nameserver = ao2_iterator_next(&it_nameservers))) {
-		res = ub_ctx_set_fwd(cfg->global->state->resolver->context, nameserver);
-
-		if (res) {
-			ast_log(LOG_ERROR, "Failed to add nameserver '%s' to unbound resolver: %s\n",
-				nameserver, ub_strerror(res));
-			ao2_iterator_destroy(&it_nameservers);
-			return -1;
-		}
-	}
-	ao2_iterator_destroy(&it_nameservers);
+	if (cfg->global->nameservers) {
+		struct ao2_iterator it_nameservers;
+		const char *nameserver;
+
+		it_nameservers = ao2_iterator_init(cfg->global->nameservers, 0);
+		while ((nameserver = ao2_iterator_next(&it_nameservers))) {
+			res = ub_ctx_set_fwd(cfg->global->state->resolver->context, nameserver);
+
+			if (res) {
+				ast_log(LOG_ERROR, "Failed to add nameserver '%s' to unbound resolver: %s\n",
+					nameserver, ub_strerror(res));
+				ao2_iterator_destroy(&it_nameservers);
+				return -1;
+			}
+		}
+		ao2_iterator_destroy(&it_nameservers);
+	}
 
 	if (!strcmp(cfg->global->resolv, "system")) {
 		res = ub_ctx_resolvconf(cfg->global->state->resolver->context, NULL);
@@ -885,6 +883,13 @@
 {
 	struct unbound_global_config *global = obj;
 
+	if (!global->nameservers) {
+		global->nameservers = ast_str_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, 1);
+		if (!global->nameservers) {
+			return -1;
+		}
+	}
+
 	return ast_str_container_add(global->nameservers, var->value);
 }
 




More information about the asterisk-commits mailing list