summaryrefslogtreecommitdiff
path: root/addrmatch.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2018-07-31 03:07:24 +0000
committerDamien Miller <djm@mindrot.org>2018-07-31 13:13:26 +1000
commit1a66079c0669813306cc69e5776a4acd9fb49015 (patch)
tree892eb2fcddac9189cc1d8e7a9b821bde27ba1014 /addrmatch.c
parent87f08be054b7eeadbb9cdeb3fb4872be79ccf218 (diff)
upstream: fix some memory leaks spotted by Coverity via Jakub Jelen
in bz#2366 feedback and ok dtucker@ OpenBSD-Commit-ID: 8402bbae67d578bedbadb0ce68ff7c5a136ef563
Diffstat (limited to 'addrmatch.c')
-rw-r--r--addrmatch.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/addrmatch.c b/addrmatch.c
index 8658e105a..5a402d065 100644
--- a/addrmatch.c
+++ b/addrmatch.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: addrmatch.c,v 1.13 2016/09/21 16:55:42 djm Exp $ */ 1/* $OpenBSD: addrmatch.c,v 1.14 2018/07/31 03:07:24 djm Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2004-2008 Damien Miller <djm@mindrot.org> 4 * Copyright (c) 2004-2008 Damien Miller <djm@mindrot.org>
@@ -205,25 +205,24 @@ addr_cmp(const struct xaddr *a, const struct xaddr *b)
205static int 205static int
206addr_pton(const char *p, struct xaddr *n) 206addr_pton(const char *p, struct xaddr *n)
207{ 207{
208 struct addrinfo hints, *ai; 208 struct addrinfo hints, *ai = NULL;
209 int ret = -1;
209 210
210 memset(&hints, '\0', sizeof(hints)); 211 memset(&hints, '\0', sizeof(hints));
211 hints.ai_flags = AI_NUMERICHOST; 212 hints.ai_flags = AI_NUMERICHOST;
212 213
213 if (p == NULL || getaddrinfo(p, NULL, &hints, &ai) != 0) 214 if (p == NULL || getaddrinfo(p, NULL, &hints, &ai) != 0)
214 return -1; 215 goto out;
215
216 if (ai == NULL || ai->ai_addr == NULL) 216 if (ai == NULL || ai->ai_addr == NULL)
217 return -1; 217 goto out;
218 218 if (n != NULL && addr_sa_to_xaddr(ai->ai_addr, ai->ai_addrlen, n) == -1)
219 if (n != NULL && 219 goto out;
220 addr_sa_to_xaddr(ai->ai_addr, ai->ai_addrlen, n) == -1) { 220 /* success */
221 ret = 0;
222 out:
223 if (ai != NULL)
221 freeaddrinfo(ai); 224 freeaddrinfo(ai);
222 return -1; 225 return ret;
223 }
224
225 freeaddrinfo(ai);
226 return 0;
227} 226}
228 227
229/* 228/*