Browse Source

inet: res_nclose: free user-buffer, not global _res

In res_iclose we were operating on the global _res even if called via
res_nclose where we are supposed to operate on the user provided
res_state.

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Bernhard Reutner-Fischer 11 years ago
parent
commit
950fcf0f68
1 changed files with 12 additions and 9 deletions
  1. 12 9
      libc/inet/resolv.c

+ 12 - 9
libc/inet/resolv.c

@@ -3531,24 +3531,27 @@ __res_vinit(res_state rp, int preinit)
 }
 
 static void
-__res_iclose(void)
+__res_iclose(res_state statp)
 {
+	struct __res_state * rp = statp;
 	__UCLIBC_MUTEX_LOCK(__resolv_lock);
+	if (rp == NULL)
+		rp = __resp;
 	__close_nameservers();
 	__res_sync = NULL;
 #ifdef __UCLIBC_HAS_IPV6__
 	{
-		char *p1 = (char*) &(_res.nsaddr_list[0]);
-		int m = 0;
+		char *p1 = (char*) &(rp->nsaddr_list[0]);
+		unsigned int m = 0;
 		/* free nsaddrs[m] if they do not point to nsaddr_list[x] */
-		while (m < ARRAY_SIZE(_res._u._ext.nsaddrs)) {
-			char *p2 = (char*)(_res._u._ext.nsaddrs[m++]);
-			if (p2 < p1 || (p2 - p1) > sizeof(_res.nsaddr_list))
+		while (m < ARRAY_SIZE(rp->_u._ext.nsaddrs)) {
+			char *p2 = (char*)(rp->_u._ext.nsaddrs[m++]);
+			if (p2 < p1 || (p2 - p1) > (signed)sizeof(rp->nsaddr_list))
 				free(p2);
 		}
 	}
 #endif
-	memset(&_res, 0, sizeof(_res));
+	memset(rp, 0, sizeof(struct __res_state));
 	__UCLIBC_MUTEX_UNLOCK(__resolv_lock);
 }
 
@@ -3563,13 +3566,13 @@ __res_iclose(void)
 void
 res_nclose(res_state statp)
 {
-	__res_iclose();
+	__res_iclose(statp);
 }
 
 #ifdef __UCLIBC_HAS_BSD_RES_CLOSE__
 void res_close(void)
 {
-	__res_iclose();
+	__res_iclose(NULL);
 }
 #endif