From 1a66079c0669813306cc69e5776a4acd9fb49015 Mon Sep 17 00:00:00 2001 From: "djm@openbsd.org" Date: Tue, 31 Jul 2018 03:07:24 +0000 Subject: upstream: fix some memory leaks spotted by Coverity via Jakub Jelen in bz#2366 feedback and ok dtucker@ OpenBSD-Commit-ID: 8402bbae67d578bedbadb0ce68ff7c5a136ef563 --- addrmatch.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'addrmatch.c') diff --git a/addrmatch.c b/addrmatch.c index 8658e105a..5a402d065 100644 --- a/addrmatch.c +++ b/addrmatch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: addrmatch.c,v 1.13 2016/09/21 16:55:42 djm Exp $ */ +/* $OpenBSD: addrmatch.c,v 1.14 2018/07/31 03:07:24 djm Exp $ */ /* * Copyright (c) 2004-2008 Damien Miller @@ -205,25 +205,24 @@ addr_cmp(const struct xaddr *a, const struct xaddr *b) static int addr_pton(const char *p, struct xaddr *n) { - struct addrinfo hints, *ai; + struct addrinfo hints, *ai = NULL; + int ret = -1; memset(&hints, '\0', sizeof(hints)); hints.ai_flags = AI_NUMERICHOST; if (p == NULL || getaddrinfo(p, NULL, &hints, &ai) != 0) - return -1; - + goto out; if (ai == NULL || ai->ai_addr == NULL) - return -1; - - if (n != NULL && - addr_sa_to_xaddr(ai->ai_addr, ai->ai_addrlen, n) == -1) { + goto out; + if (n != NULL && addr_sa_to_xaddr(ai->ai_addr, ai->ai_addrlen, n) == -1) + goto out; + /* success */ + ret = 0; + out: + if (ai != NULL) freeaddrinfo(ai); - return -1; - } - - freeaddrinfo(ai); - return 0; + return ret; } /* -- cgit v1.2.3