This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH v1.1] Deduplicate resolv/nss_dns/dns-host.c
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Mike Frysinger <vapier at gentoo dot org>
- Cc: libc-alpha at sourceware dot org
- Date: Sat, 15 Feb 2014 12:39:19 +0100
- Subject: [PATCH v1.1] Deduplicate resolv/nss_dns/dns-host.c
- Authentication-results: sourceware.org; auth=none
- References: <20140213123812 dot GB14778 at domone dot podge> <2173663 dot ICIzkxrumV at vapier>
On Fri, Feb 14, 2014 at 12:25:51PM -0500, Mike Frysinger wrote:
> On Thursday, February 13, 2014 13:38:12 OndÅej BÃlka wrote:
> > Hi, when reviewing Andreas patch I noticed duplicated code. One way to
> > improve that is jump to exit logic. A second possibility would be put
> > gaih_getanswer into a else block. What do you prefer?
>
> i don't mind either, but i think generally the preference is to avoid goto
> when easily possible. so in this case, use the else.
> -mike
OK, patch for this is following. It should cover one extra possibility when
__libc_res_nsearch fails and allocates separate buffer.
* resolv/nss_dns/dns-host.c (_nss_dns_gethostbyname4_r): Remove
duplicate code
diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
index 365de70..47f998c 100644
--- a/resolv/nss_dns/dns-host.c
+++ b/resolv/nss_dns/dns-host.c
@@ -315,7 +315,13 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
int n = __libc_res_nsearch (&_res, name, C_IN, T_UNSPEC,
host_buffer.buf->buf, anslen, &host_buffer.ptr,
&ans2p, &nans2p, &resplen2);
- if (n < 0)
+ if (n >= 0)
+ {
+ status = gaih_getanswer (host_buffer.buf, n, (const querybuf *) ans2p,
+ resplen2, name, pat, buffer, buflen,
+ errnop, herrnop, ttlp);
+ }
+ else
{
switch (errno)
{
@@ -342,17 +348,8 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
*errnop = EAGAIN;
else
__set_errno (olderr);
-
- if (host_buffer.buf != orig_host_buffer)
- free (host_buffer.buf);
-
- return status;
}
- status = gaih_getanswer(host_buffer.buf, n, (const querybuf *) ans2p,
- resplen2, name, pat, buffer, buflen,
- errnop, herrnop, ttlp);
-
/* Check whether ans2p was separately allocated. */
if (host_buffer.buf != orig_host_buffer)
anslen = MAXPACKET;