[Asterisk-code-review] res resolver unbound: Fix leak of config nameserver strings. (asterisk[master])

Joshua Colp asteriskteam at digium.com
Fri Aug 17 05:40:01 CDT 2018


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/9888 )

Change subject: res_resolver_unbound: Fix leak of config nameserver strings.
......................................................................

res_resolver_unbound: Fix leak of config nameserver strings.

Change-Id: I3f396316bb40d1ae6e91f5f688042420f1a540ed
---
M res/res_resolver_unbound.c
1 file changed, 6 insertions(+), 4 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit
  George Joseph: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, approved



diff --git a/res/res_resolver_unbound.c b/res/res_resolver_unbound.c
index 25f6150..89a934c 100644
--- a/res/res_resolver_unbound.c
+++ b/res/res_resolver_unbound.c
@@ -432,20 +432,22 @@
 
 	if (cfg->global->nameservers) {
 		struct ao2_iterator it_nameservers;
-		const char *nameserver;
+		char *nameserver;
 
 		it_nameservers = ao2_iterator_init(cfg->global->nameservers, 0);
-		while ((nameserver = ao2_iterator_next(&it_nameservers))) {
+		while (!res && (nameserver = ao2_iterator_next(&it_nameservers))) {
 			res = ub_ctx_set_fwd(cfg->global->state->resolver->context, (UNBOUND_CHAR *)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_ref(nameserver, -1);
 		}
 		ao2_iterator_destroy(&it_nameservers);
+		if (res) {
+			return -1;
+		}
 	}
 
 	if (!strcmp(cfg->global->resolv, "system")) {

-- 
To view, visit https://gerrit.asterisk.org/9888
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I3f396316bb40d1ae6e91f5f688042420f1a540ed
Gerrit-Change-Number: 9888
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180817/476e890c/attachment.html>


More information about the asterisk-code-review mailing list