00db10
Sourceware bug 16574
00db10
00db10
commit d668061994a7486a3ba9c7d5e7882d85a2883707
00db10
Author: Andreas Schwab <schwab@suse.de>
00db10
Date:   Thu Feb 13 11:01:57 2014 +0100
00db10
00db10
    Fix memory leak in _nss_dns_gethostbyname4_r with big DNS answer
00db10
00db10
commit ab7ac0f2cf8731fe4c3f3aea6088a7c0127b5725
00db10
Author: Ondřej Bílka <neleai@seznam.cz>
00db10
Date:   Sun Feb 16 12:59:23 2014 +0100
00db10
00db10
    Deduplicate resolv/nss_dns/dns-host.c
00db10
    
00db10
    In resolv/nss_dns/dns-host.c one of code path duplicated code after
00db10
    that. We merge these paths.
00db10
00db10
commit ab09bf616ad527b249aca5f2a4956fd526f0712f
00db10
Author: Andreas Schwab <schwab@suse.de>
00db10
Date:   Tue Feb 18 10:57:25 2014 +0100
00db10
00db10
    Properly fix memory leak in _nss_dns_gethostbyname4_r with big DNS answer
00db10
    
00db10
    Instead of trying to guess whether the second buffer needs to be freed
00db10
    set a flag at the place it is allocated
00db10
00db10
Index: glibc-2.17-c758a686/include/resolv.h
00db10
===================================================================
00db10
--- glibc-2.17-c758a686.orig/include/resolv.h
00db10
+++ glibc-2.17-c758a686/include/resolv.h
00db10
@@ -56,11 +56,11 @@ libc_hidden_proto (__res_randomid)
00db10
 libc_hidden_proto (__res_state)
00db10
 
00db10
 int __libc_res_nquery (res_state, const char *, int, int, u_char *, int,
00db10
-		       u_char **, u_char **, int *, int *);
00db10
+		       u_char **, u_char **, int *, int *, int *);
00db10
 int __libc_res_nsearch (res_state, const char *, int, int, u_char *, int,
00db10
-			u_char **, u_char **, int *, int *);
00db10
+			u_char **, u_char **, int *, int *, int *);
00db10
 int __libc_res_nsend (res_state, const u_char *, int, const u_char *, int,
00db10
-		      u_char *, int, u_char **, u_char **, int *, int *)
00db10
+		      u_char *, int, u_char **, u_char **, int *, int *, int *)
00db10
   attribute_hidden;
00db10
 
00db10
 libresolv_hidden_proto (_sethtent)
00db10
Index: glibc-2.17-c758a686/resolv/gethnamaddr.c
00db10
===================================================================
00db10
--- glibc-2.17-c758a686.orig/resolv/gethnamaddr.c
00db10
+++ glibc-2.17-c758a686/resolv/gethnamaddr.c
00db10
@@ -616,7 +616,7 @@ gethostbyname2(name, af)
00db10
 	buf.buf = origbuf = (querybuf *) alloca (1024);
00db10
 
00db10
 	if ((n = __libc_res_nsearch(&_res, name, C_IN, type, buf.buf->buf, 1024,
00db10
-				    &buf.ptr, NULL, NULL, NULL)) < 0) {
00db10
+				    &buf.ptr, NULL, NULL, NULL, NULL)) < 0) {
00db10
 		if (buf.buf != origbuf)
00db10
 			free (buf.buf);
00db10
 		Dprintf("res_nsearch failed (%d)\n", n);
00db10
@@ -711,12 +711,12 @@ gethostbyaddr(addr, len, af)
00db10
 	buf.buf = orig_buf = (querybuf *) alloca (1024);
00db10
 
00db10
 	n = __libc_res_nquery(&_res, qbuf, C_IN, T_PTR, buf.buf->buf, 1024,
00db10
-			      &buf.ptr, NULL, NULL, NULL);
00db10
+			      &buf.ptr, NULL, NULL, NULL, NULL);
00db10
 	if (n < 0 && af == AF_INET6 && (_res.options & RES_NOIP6DOTINT) == 0) {
00db10
 		strcpy(qp, "ip6.int");
00db10
 		n = __libc_res_nquery(&_res, qbuf, C_IN, T_PTR, buf.buf->buf,
00db10
 				      buf.buf != orig_buf ? MAXPACKET : 1024,
00db10
-				      &buf.ptr, NULL, NULL, NULL);
00db10
+				      &buf.ptr, NULL, NULL, NULL, NULL);
00db10
 	}
00db10
 	if (n < 0) {
00db10
 		if (buf.buf != orig_buf)
00db10
Index: glibc-2.17-c758a686/resolv/nss_dns/dns-canon.c
00db10
===================================================================
00db10
--- glibc-2.17-c758a686.orig/resolv/nss_dns/dns-canon.c
00db10
+++ glibc-2.17-c758a686/resolv/nss_dns/dns-canon.c
00db10
@@ -61,7 +61,7 @@ _nss_dns_getcanonname_r (const char *nam
00db10
     {
00db10
       int r = __libc_res_nquery (&_res, name, ns_c_in, qtypes[i],
00db10
 				 buf, sizeof (buf), &ansp.ptr, NULL, NULL,
00db10
-				 NULL);
00db10
+				 NULL, NULL);
00db10
       if (r > 0)
00db10
 	{
00db10
 	  /* We need to decode the response.  Just one question record.
00db10
Index: glibc-2.17-c758a686/resolv/nss_dns/dns-host.c
00db10
===================================================================
00db10
--- glibc-2.17-c758a686.orig/resolv/nss_dns/dns-host.c
00db10
+++ glibc-2.17-c758a686/resolv/nss_dns/dns-host.c
00db10
@@ -190,7 +190,7 @@ _nss_dns_gethostbyname3_r (const char *n
00db10
   host_buffer.buf = orig_host_buffer = (querybuf *) alloca (1024);
00db10
 
00db10
   n = __libc_res_nsearch (&_res, name, C_IN, type, host_buffer.buf->buf,
00db10
-			  1024, &host_buffer.ptr, NULL, NULL, NULL);
00db10
+			  1024, &host_buffer.ptr, NULL, NULL, NULL, NULL);
00db10
   if (n < 0)
00db10
     {
00db10
       switch (errno)
00db10
@@ -225,7 +225,7 @@ _nss_dns_gethostbyname3_r (const char *n
00db10
 	n = __libc_res_nsearch (&_res, name, C_IN, T_A, host_buffer.buf->buf,
00db10
 				host_buffer.buf != orig_host_buffer
00db10
 				? MAXPACKET : 1024, &host_buffer.ptr,
00db10
-				NULL, NULL, NULL);
00db10
+				NULL, NULL, NULL, NULL);
00db10
 
00db10
       if (n < 0)
00db10
 	{
00db10
@@ -308,13 +308,20 @@ _nss_dns_gethostbyname4_r (const char *n
00db10
   u_char *ans2p = NULL;
00db10
   int nans2p = 0;
00db10
   int resplen2 = 0;
00db10
+  int ans2p_malloced = 0;
00db10
 
00db10
   int olderr = errno;
00db10
   enum nss_status status;
00db10
   int n = __libc_res_nsearch (&_res, name, C_IN, T_UNSPEC,
00db10
 			      host_buffer.buf->buf, 2048, &host_buffer.ptr,
00db10
-			      &ans2p, &nans2p, &resplen2);
00db10
-  if (n < 0)
00db10
+			      &ans2p, &nans2p, &resplen2, &ans2p_malloced);
00db10
+  if (n >= 0)
00db10
+    {
00db10
+      status = gaih_getanswer (host_buffer.buf, n, (const querybuf *) ans2p,
00db10
+			       resplen2, name, pat, buffer, buflen,
00db10
+			       errnop, herrnop, ttlp);
00db10
+    }
00db10
+  else
00db10
     {
00db10
       switch (errno)
00db10
 	{
00db10
@@ -341,16 +348,11 @@ _nss_dns_gethostbyname4_r (const char *n
00db10
 	*errnop = EAGAIN;
00db10
       else
00db10
 	__set_errno (olderr);
00db10
-
00db10
-      if (host_buffer.buf != orig_host_buffer)
00db10
-	free (host_buffer.buf);
00db10
-
00db10
-      return status;
00db10
     }
00db10
 
00db10
-  status = gaih_getanswer(host_buffer.buf, n, (const querybuf *) ans2p,
00db10
-			  resplen2, name, pat, buffer, buflen,
00db10
-			  errnop, herrnop, ttlp);
00db10
+  /* Check whether ans2p was separately allocated.  */
00db10
+  if (ans2p_malloced)
00db10
+    free (ans2p);
00db10
 
00db10
   if (host_buffer.buf != orig_host_buffer)
00db10
     free (host_buffer.buf);
00db10
@@ -460,7 +462,7 @@ _nss_dns_gethostbyaddr2_r (const void *a
00db10
 	  strcpy (qp, "].ip6.arpa");
00db10
 	  n = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR,
00db10
 				 host_buffer.buf->buf, 1024, &host_buffer.ptr,
00db10
-				 NULL, NULL, NULL);
00db10
+				 NULL, NULL, NULL, NULL);
00db10
 	  if (n >= 0)
00db10
 	    goto got_it_already;
00db10
 	}
00db10
@@ -481,14 +483,14 @@ _nss_dns_gethostbyaddr2_r (const void *a
00db10
     }
00db10
 
00db10
   n = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, host_buffer.buf->buf,
00db10
-			 1024, &host_buffer.ptr, NULL, NULL, NULL);
00db10
+			 1024, &host_buffer.ptr, NULL, NULL, NULL, NULL);
00db10
   if (n < 0 && af == AF_INET6 && (_res.options & RES_NOIP6DOTINT) == 0)
00db10
     {
00db10
       strcpy (qp, "ip6.int");
00db10
       n = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, host_buffer.buf->buf,
00db10
 			     host_buffer.buf != orig_host_buffer
00db10
 			     ? MAXPACKET : 1024, &host_buffer.ptr,
00db10
-			     NULL, NULL, NULL);
00db10
+			     NULL, NULL, NULL, NULL);
00db10
     }
00db10
   if (n < 0)
00db10
     {
00db10
Index: glibc-2.17-c758a686/resolv/nss_dns/dns-network.c
00db10
===================================================================
00db10
--- glibc-2.17-c758a686.orig/resolv/nss_dns/dns-network.c
00db10
+++ glibc-2.17-c758a686/resolv/nss_dns/dns-network.c
00db10
@@ -129,7 +129,7 @@ _nss_dns_getnetbyname_r (const char *nam
00db10
   net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024);
00db10
 
00db10
   anslen = __libc_res_nsearch (&_res, qbuf, C_IN, T_PTR, net_buffer.buf->buf,
00db10
-			       1024, &net_buffer.ptr, NULL, NULL, NULL);
00db10
+			       1024, &net_buffer.ptr, NULL, NULL, NULL, NULL);
00db10
   if (anslen < 0)
00db10
     {
00db10
       /* Nothing found.  */
00db10
@@ -205,7 +205,7 @@ _nss_dns_getnetbyaddr_r (uint32_t net, i
00db10
   net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024);
00db10
 
00db10
   anslen = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, net_buffer.buf->buf,
00db10
-			      1024, &net_buffer.ptr, NULL, NULL, NULL);
00db10
+			      1024, &net_buffer.ptr, NULL, NULL, NULL, NULL);
00db10
   if (anslen < 0)
00db10
     {
00db10
       /* Nothing found.  */
00db10
Index: glibc-2.17-c758a686/resolv/res_query.c
00db10
===================================================================
00db10
--- glibc-2.17-c758a686.orig/resolv/res_query.c
00db10
+++ glibc-2.17-c758a686/resolv/res_query.c
00db10
@@ -98,7 +98,7 @@ static int
00db10
 __libc_res_nquerydomain(res_state statp, const char *name, const char *domain,
00db10
 			int class, int type, u_char *answer, int anslen,
00db10
 			u_char **answerp, u_char **answerp2, int *nanswerp2,
00db10
-			int *resplen2);
00db10
+			int *resplen2, int *answerp2_malloced);
00db10
 
00db10
 /*
00db10
  * Formulate a normal query, send, and await answer.
00db10
@@ -119,7 +119,8 @@ __libc_res_nquery(res_state statp,
00db10
 		  u_char **answerp,	/* if buffer needs to be enlarged */
00db10
 		  u_char **answerp2,
00db10
 		  int *nanswerp2,
00db10
-		  int *resplen2)
00db10
+		  int *resplen2,
00db10
+		  int *answerp2_malloced)
00db10
 {
00db10
 	HEADER *hp = (HEADER *) answer;
00db10
 	HEADER *hp2;
00db10
@@ -224,7 +225,8 @@ __libc_res_nquery(res_state statp,
00db10
 	}
00db10
 	assert (answerp == NULL || (void *) *answerp == (void *) answer);
00db10
 	n = __libc_res_nsend(statp, query1, nquery1, query2, nquery2, answer,
00db10
-			     anslen, answerp, answerp2, nanswerp2, resplen2);
00db10
+			     anslen, answerp, answerp2, nanswerp2, resplen2,
00db10
+			     answerp2_malloced);
00db10
 	if (use_malloc)
00db10
 		free (buf);
00db10
 	if (n < 0) {
00db10
@@ -316,7 +318,7 @@ res_nquery(res_state statp,
00db10
 	   int anslen)		/* size of answer buffer */
00db10
 {
00db10
 	return __libc_res_nquery(statp, name, class, type, answer, anslen,
00db10
-				 NULL, NULL, NULL, NULL);
00db10
+				 NULL, NULL, NULL, NULL, NULL);
00db10
 }
00db10
 libresolv_hidden_def (res_nquery)
00db10
 
00db10
@@ -335,7 +337,8 @@ __libc_res_nsearch(res_state statp,
00db10
 		   u_char **answerp,
00db10
 		   u_char **answerp2,
00db10
 		   int *nanswerp2,
00db10
-		   int *resplen2)
00db10
+		   int *resplen2,
00db10
+		   int *answerp2_malloced)
00db10
 {
00db10
 	const char *cp, * const *domain;
00db10
 	HEADER *hp = (HEADER *) answer;
00db10
@@ -360,7 +363,7 @@ __libc_res_nsearch(res_state statp,
00db10
 	if (!dots && (cp = res_hostalias(statp, name, tmp, sizeof tmp))!= NULL)
00db10
 		return (__libc_res_nquery(statp, cp, class, type, answer,
00db10
 					  anslen, answerp, answerp2,
00db10
-					  nanswerp2, resplen2));
00db10
+					  nanswerp2, resplen2, answerp2_malloced));
00db10
 
00db10
 #ifdef DEBUG
00db10
 	if (statp->options & RES_DEBUG)
00db10
@@ -377,7 +380,8 @@ __libc_res_nsearch(res_state statp,
00db10
 	if (dots >= statp->ndots || trailing_dot) {
00db10
 		ret = __libc_res_nquerydomain(statp, name, NULL, class, type,
00db10
 					      answer, anslen, answerp,
00db10
-					      answerp2, nanswerp2, resplen2);
00db10
+					      answerp2, nanswerp2, resplen2,
00db10
+					      answerp2_malloced);
00db10
 		if (ret > 0 || trailing_dot
00db10
 		    /* If the second response is valid then we use that.  */
00db10
 		    || (ret == 0 && resplen2 != NULL && *resplen2 > 0))
00db10
@@ -388,11 +392,11 @@ __libc_res_nsearch(res_state statp,
00db10
 			answer = *answerp;
00db10
 			anslen = MAXPACKET;
00db10
 		}
00db10
-		if (answerp2
00db10
-		    && (*answerp2 < answer || *answerp2 >= answer + anslen))
00db10
+		if (answerp2 && *answerp2_malloced)
00db10
 		  {
00db10
 		    free (*answerp2);
00db10
 		    *answerp2 = NULL;
00db10
+		    *answerp2_malloced = 0;
00db10
 		  }
00db10
 	}
00db10
 
00db10
@@ -419,7 +423,7 @@ __libc_res_nsearch(res_state statp,
00db10
 						      class, type,
00db10
 						      answer, anslen, answerp,
00db10
 						      answerp2, nanswerp2,
00db10
-						      resplen2);
00db10
+						      resplen2, answerp2_malloced);
00db10
 			if (ret > 0 || (ret == 0 && resplen2 != NULL
00db10
 					&& *resplen2 > 0))
00db10
 				return (ret);
00db10
@@ -428,12 +432,11 @@ __libc_res_nsearch(res_state statp,
00db10
 				answer = *answerp;
00db10
 				anslen = MAXPACKET;
00db10
 			}
00db10
-			if (answerp2
00db10
-			    && (*answerp2 < answer
00db10
-				|| *answerp2 >= answer + anslen))
00db10
+			if (answerp2 && *answerp2_malloced)
00db10
 			  {
00db10
 			    free (*answerp2);
00db10
 			    *answerp2 = NULL;
00db10
+			    *answerp2_malloced = 0;
00db10
 			  }
00db10
 
00db10
 			/*
00db10
@@ -489,7 +492,8 @@ __libc_res_nsearch(res_state statp,
00db10
 	    && !(tried_as_is || root_on_list)) {
00db10
 		ret = __libc_res_nquerydomain(statp, name, NULL, class, type,
00db10
 					      answer, anslen, answerp,
00db10
-					      answerp2, nanswerp2, resplen2);
00db10
+					      answerp2, nanswerp2, resplen2,
00db10
+					      answerp2_malloced);
00db10
 		if (ret > 0 || (ret == 0 && resplen2 != NULL
00db10
 				&& *resplen2 > 0))
00db10
 			return (ret);
00db10
@@ -502,10 +506,11 @@ __libc_res_nsearch(res_state statp,
00db10
 	 * else send back meaningless H_ERRNO, that being the one from
00db10
 	 * the last DNSRCH we did.
00db10
 	 */
00db10
-	if (answerp2 && (*answerp2 < answer || *answerp2 >= answer + anslen))
00db10
+	if (answerp2 && *answerp2_malloced)
00db10
 	  {
00db10
 	    free (*answerp2);
00db10
 	    *answerp2 = NULL;
00db10
+	    *answerp2_malloced = 0;
00db10
 	  }
00db10
 	if (saved_herrno != -1)
00db10
 		RES_SET_H_ERRNO(statp, saved_herrno);
00db10
@@ -525,7 +530,7 @@ res_nsearch(res_state statp,
00db10
 	    int anslen)		/* size of answer */
00db10
 {
00db10
 	return __libc_res_nsearch(statp, name, class, type, answer,
00db10
-				  anslen, NULL, NULL, NULL, NULL);
00db10
+				  anslen, NULL, NULL, NULL, NULL, NULL);
00db10
 }
00db10
 libresolv_hidden_def (res_nsearch)
00db10
 
00db10
@@ -543,7 +548,8 @@ __libc_res_nquerydomain(res_state statp,
00db10
 			u_char **answerp,
00db10
 			u_char **answerp2,
00db10
 			int *nanswerp2,
00db10
-			int *resplen2)
00db10
+			int *resplen2,
00db10
+			int *answerp2_malloced)
00db10
 {
00db10
 	char nbuf[MAXDNAME];
00db10
 	const char *longname = nbuf;
00db10
@@ -585,7 +591,7 @@ __libc_res_nquerydomain(res_state statp,
00db10
 	}
00db10
 	return (__libc_res_nquery(statp, longname, class, type, answer,
00db10
 				  anslen, answerp, answerp2, nanswerp2,
00db10
-				  resplen2));
00db10
+				  resplen2, answerp2_malloced));
00db10
 }
00db10
 
00db10
 int
00db10
@@ -597,7 +603,8 @@ res_nquerydomain(res_state statp,
00db10
 	    int anslen)		/* size of answer */
00db10
 {
00db10
 	return __libc_res_nquerydomain(statp, name, domain, class, type,
00db10
-				       answer, anslen, NULL, NULL, NULL, NULL);
00db10
+				       answer, anslen, NULL, NULL, NULL, NULL,
00db10
+				       NULL);
00db10
 }
00db10
 libresolv_hidden_def (res_nquerydomain)
00db10
 
00db10
Index: glibc-2.17-c758a686/resolv/res_send.c
00db10
===================================================================
00db10
--- glibc-2.17-c758a686.orig/resolv/res_send.c
00db10
+++ glibc-2.17-c758a686/resolv/res_send.c
00db10
@@ -186,12 +186,12 @@ evNowTime(struct timespec *res) {
00db10
 static int		send_vc(res_state, const u_char *, int,
00db10
 				const u_char *, int,
00db10
 				u_char **, int *, int *, int, u_char **,
00db10
-				u_char **, int *, int *);
00db10
+				u_char **, int *, int *, int *);
00db10
 static int		send_dg(res_state, const u_char *, int,
00db10
 				const u_char *, int,
00db10
 				u_char **, int *, int *, int,
00db10
 				int *, int *, u_char **,
00db10
-				u_char **, int *, int *);
00db10
+				u_char **, int *, int *, int *);
00db10
 #ifdef DEBUG
00db10
 static void		Aerror(const res_state, FILE *, const char *, int,
00db10
 			       const struct sockaddr *);
00db10
@@ -343,7 +343,7 @@ int
00db10
 __libc_res_nsend(res_state statp, const u_char *buf, int buflen,
00db10
 		 const u_char *buf2, int buflen2,
00db10
 		 u_char *ans, int anssiz, u_char **ansp, u_char **ansp2,
00db10
-		 int *nansp2, int *resplen2)
00db10
+		 int *nansp2, int *resplen2, int *ansp2_malloced)
00db10
 {
00db10
   int gotsomewhere, terrno, try, v_circuit, resplen, ns, n;
00db10
 
00db10
@@ -546,7 +546,8 @@ __libc_res_nsend(res_state statp, const
00db10
 			try = statp->retry;
00db10
 			n = send_vc(statp, buf, buflen, buf2, buflen2,
00db10
 				    &ans, &anssiz, &terrno,
00db10
-				    ns, ansp, ansp2, nansp2, resplen2);
00db10
+				    ns, ansp, ansp2, nansp2, resplen2,
00db10
+				    ansp2_malloced);
00db10
 			if (n < 0)
00db10
 				return (-1);
00db10
 			if (n == 0 && (buf2 == NULL || *resplen2 == 0))
00db10
@@ -556,7 +557,7 @@ __libc_res_nsend(res_state statp, const
00db10
 			n = send_dg(statp, buf, buflen, buf2, buflen2,
00db10
 				    &ans, &anssiz, &terrno,
00db10
 				    ns, &v_circuit, &gotsomewhere, ansp,
00db10
-				    ansp2, nansp2, resplen2);
00db10
+				    ansp2, nansp2, resplen2, ansp2_malloced);
00db10
 			if (n < 0)
00db10
 				return (-1);
00db10
 			if (n == 0 && (buf2 == NULL || *resplen2 == 0))
00db10
@@ -646,7 +647,7 @@ res_nsend(res_state statp,
00db10
 	  const u_char *buf, int buflen, u_char *ans, int anssiz)
00db10
 {
00db10
   return __libc_res_nsend(statp, buf, buflen, NULL, 0, ans, anssiz,
00db10
-			  NULL, NULL, NULL, NULL);
00db10
+			  NULL, NULL, NULL, NULL, NULL);
00db10
 }
00db10
 libresolv_hidden_def (res_nsend)
00db10
 
00db10
@@ -657,7 +658,7 @@ send_vc(res_state statp,
00db10
 	const u_char *buf, int buflen, const u_char *buf2, int buflen2,
00db10
 	u_char **ansp, int *anssizp,
00db10
 	int *terrno, int ns, u_char **anscp, u_char **ansp2, int *anssizp2,
00db10
-	int *resplen2)
00db10
+	int *resplen2, int *ansp2_malloced)
00db10
 {
00db10
 	const HEADER *hp = (HEADER *) buf;
00db10
 	const HEADER *hp2 = (HEADER *) buf2;
00db10
@@ -823,6 +824,8 @@ send_vc(res_state statp,
00db10
 			}
00db10
 			*thisanssizp = MAXPACKET;
00db10
 			*thisansp = newp;
00db10
+			if (thisansp == ansp2)
00db10
+			  *ansp2_malloced = 1;
00db10
 			anhp = (HEADER *) newp;
00db10
 			len = rlen;
00db10
 		} else {
00db10
@@ -992,7 +995,7 @@ send_dg(res_state statp,
00db10
 	const u_char *buf, int buflen, const u_char *buf2, int buflen2,
00db10
 	u_char **ansp, int *anssizp,
00db10
 	int *terrno, int ns, int *v_circuit, int *gotsomewhere, u_char **anscp,
00db10
-	u_char **ansp2, int *anssizp2, int *resplen2)
00db10
+	u_char **ansp2, int *anssizp2, int *resplen2, int *ansp2_malloced)
00db10
 {
00db10
 	const HEADER *hp = (HEADER *) buf;
00db10
 	const HEADER *hp2 = (HEADER *) buf2;
00db10
@@ -1235,6 +1238,8 @@ send_dg(res_state statp,
00db10
 			if (newp != NULL) {
00db10
 				*anssizp = MAXPACKET;
00db10
 				*thisansp = ans = newp;
00db10
+				if (thisansp == ansp2)
00db10
+				  *ansp2_malloced = 1;
00db10
 			}
00db10
 		}
00db10
 		HEADER *anhp = (HEADER *) *thisansp;