From 25e8fca7b4af13e5947fc77a2351d4213aaf4d08 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 5 Oct 2014 10:21:18 +0200 Subject: [PATCH] lib/fetch/common.c: fix CID 62681 correctly (resource leak). --- lib/fetch/common.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/fetch/common.c b/lib/fetch/common.c index 441a2d3f..c212c5fb 100644 --- a/lib/fetch/common.c +++ b/lib/fetch/common.c @@ -253,6 +253,7 @@ int fetch_bind(int sd, int af, const char *addr) { struct addrinfo hints, *res, *res0; + int rv = -1; memset(&hints, 0, sizeof(hints)); hints.ai_family = af; @@ -261,11 +262,13 @@ fetch_bind(int sd, int af, const char *addr) if (getaddrinfo(addr, NULL, &hints, &res0)) return (-1); for (res = res0; res; res = res->ai_next) { - if (bind(sd, res->ai_addr, res->ai_addrlen) == 0) - return (0); + if (bind(sd, res->ai_addr, res->ai_addrlen) == 0) { + rv = 0; + break; + } } freeaddrinfo(res0); - return (-1); + return rv; }