[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Backport fix to getaddrinfo mem leak



Update of /home/or/cvsroot/tor/src/common
In directory moria:/tmp/cvs-serv22067/src/common

Modified Files:
      Tag: tor-0_1_0-patches
	compat.c 
Log Message:
Backport fix to getaddrinfo mem leak

Index: compat.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/compat.c,v
retrieving revision 1.47
retrieving revision 1.47.2.1
diff -u -d -r1.47 -r1.47.2.1
--- compat.c	2 May 2005 21:49:04 -0000	1.47
+++ compat.c	7 Jun 2005 18:04:37 -0000	1.47.2.1
@@ -526,8 +526,9 @@
   } else {
 #ifdef HAVE_GETADDRINFO
     int err;
-    struct addrinfo *res, *res_p;
+    struct addrinfo *res=NULL, *res_p;
     struct addrinfo hints;
+    int result = -1;
     memset(&hints, 0, sizeof(hints));
     hints.ai_family = PF_INET;
     hints.ai_socktype = SOCK_STREAM;
@@ -537,14 +538,13 @@
         if (res_p->ai_family == AF_INET) {
           struct sockaddr_in *sin = (struct sockaddr_in *)res_p->ai_addr;
           memcpy(addr, &sin->sin_addr, 4);
-          freeaddrinfo(res);
-          return 0;
-        } else {
+          result = 0;
+          break;
         }
       }
-      return -1;
+      freeaddrinfo(res);
+      return result;
     }
-
     return (err == EAI_AGAIN) ? 1 : -1;
 #else
     struct hostent *ent;