]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
pullup:
authorMark Andrews <marka@isc.org>
Fri, 9 Sep 2005 00:40:56 +0000 (00:40 +0000)
committerMark Andrews <marka@isc.org>
Fri, 9 Sep 2005 00:40:56 +0000 (00:40 +0000)
res_init()/res_ninit() could leak memory when re-called.

lib/bind/resolv/res_init.c

index feefa1740f135c5b794a75908590b1b004cc0cf0..ba5d7f7039d5510db90fb09b8208e4883a5d68b5 100644 (file)
@@ -70,7 +70,7 @@
 
 #if defined(LIBC_SCCS) && !defined(lint)
 static const char sccsid[] = "@(#)res_init.c   8.1 (Berkeley) 6/7/93";
-static const char rcsid[] = "$Id: res_init.c,v 1.9.2.5.4.3 2005/07/28 07:43:22 marka Exp $";
+static const char rcsid[] = "$Id: res_init.c,v 1.9.2.5.4.4 2005/09/09 00:40:56 marka Exp $";
 #endif /* LIBC_SCCS and not lint */
 
 #include "port_before.h"
@@ -167,6 +167,9 @@ __res_vinit(res_state statp, int preinit) {
        int dots;
        union res_sockaddr_union u[2];
 
+       if (statp->_u._ext.ext != NULL)
+               res_ndestroy(statp);
+
        if (!preinit) {
                statp->retrans = RES_TIMEOUT;
                statp->retry = RES_DFLRETRY;
@@ -174,9 +177,6 @@ __res_vinit(res_state statp, int preinit) {
                statp->id = res_randomid();
        }
 
-       if ((statp->options & RES_INIT) != 0U)
-               res_ndestroy(statp);
-
        memset(u, 0, sizeof(u));
 #ifdef USELOOPBACK
        u[nserv].sin.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
@@ -240,12 +240,12 @@ __res_vinit(res_state statp, int preinit) {
                                if (strlcpy(statp->defdname, buf,
                                        sizeof(statp->defdname))
                                        >= sizeof(statp->defdname))
-                                       return (-1);
+                                       goto freedata;
                        } else {
                                if (strlcpy(statp->defdname, cp+1,
                                        sizeof(statp->defdname))
                                         >= sizeof(statp->defdname))
-                                       return (-1);
+                                       goto freedata;
                        }
                }
        }
@@ -489,6 +489,15 @@ __res_vinit(res_state statp, int preinit) {
                res_setoptions(statp, cp, "env");
        statp->options |= RES_INIT;
        return (0);
+
+#ifdef SOLARIS2
+ freedata:
+       if (statp->_u._ext.ext != NULL) {
+               free(statp->_u._ext.ext);
+               statp->_u._ext.ext = NULL;
+       }
+       return (-1);
+#endif
 }
 
 static void