pullup from trunk
authorTom Yu <tlyu@mit.edu>
Sat, 15 Jan 2005 00:10:53 +0000 (00:10 +0000)
committerTom Yu <tlyu@mit.edu>
Sat, 15 Jan 2005 00:10:53 +0000 (00:10 +0000)
ticket: 2872
version_fixed: 1.4

git-svn-id: svn://anonsvn.mit.edu/krb5/branches/krb5-1-4@17042 dc483132-0cff-0310-8789-dd5450dbe970

src/ChangeLog
src/aclocal.m4
src/lib/krb5/os/ChangeLog
src/lib/krb5/os/dnsglue.c

index 0094190e1778eb214b1e1aaa78a925f53cab9ad4..e053ae05d74668eba21b873fe2c73276edbdc443 100644 (file)
@@ -1,3 +1,7 @@
+2005-01-12  Tom Yu  <tlyu@mit.edu>
+
+       * aclocal.m4 (AC_LIBRARY_NET): Also check for res_ndestroy.
+
 2004-12-16  Ezra Peisach  <epeisach@bu.edu>
 
        * krb5-config.in: Add krb5support library.
index 595e41dd4764f9654e42b957b7aee1da1d64db7c..d135d5c10cab9cc04d4be21da7a6fcff4d1e5c2f 100644 (file)
@@ -1379,7 +1379,7 @@ AC_DEFUN(AC_LIBRARY_NET, [
     # This may get us a gethostby* that doesn't respect nsswitch.
     AC_CHECK_LIB(resolv, main)
 _KRB5_AC_CHECK_RES_FUNCS(res_nsearch res_search ns_initparse dnl
-ns_name_uncompress dn_skipname)
+ns_name_uncompress dn_skipname res_ndestroy)
     if test $krb5_cv_func_res_nsearch = no \
       && test $krb5_cv_func_res_search = no; then
        # Attempt to link with res_search(), in case it's not prototyped.
index 00b7cb8358812011b392cd1f4862750028e3ee77..469bdacf3f412a33c6f549ecf73745255eb7cfbd 100644 (file)
@@ -1,3 +1,10 @@
+2005-01-12  Tom Yu  <tlyu@mit.edu>
+
+       * dnsglue.c (krb5int_dns_fini): Reorder to make more correct.
+       (krb5int_dns_init): Rework error handling.  Call res_ndestroy() or
+       res_nclose() as appropriate to avoid leaking resources allocated
+       by res_ninit().
+
 2005-01-03  Jeffrey Altman <jaltman@mit.edu>
 
         * thread_safe.c: (new file) krb5_is_thread_safe()
index dba1b869c238b384a16947eae5291291cbcafd06..5d2db36952642f9b7f0d3ed04a71f482df4cc21b 100644 (file)
@@ -65,7 +65,7 @@ krb5int_dns_init(struct krb5int_dns_state **dsp,
     struct __res_state statbuf;
 #endif
     struct krb5int_dns_state *ds;
-    int len;
+    int len, ret;
     size_t nextincr, maxincr;
     unsigned char *p;
 
@@ -73,6 +73,7 @@ krb5int_dns_init(struct krb5int_dns_state **dsp,
     if (ds == NULL)
        return -1;
 
+    ret = -1;
     ds->nclass = nclass;
     ds->ntype = ntype;
     ds->ansp = NULL;
@@ -86,8 +87,8 @@ krb5int_dns_init(struct krb5int_dns_state **dsp,
 #endif
 
 #if HAVE_RES_NSEARCH
-    len = res_ninit(&statbuf);
-    if (len < 0)
+    ret = res_ninit(&statbuf);
+    if (ret < 0)
        return -1;
 #endif
 
@@ -96,8 +97,8 @@ krb5int_dns_init(struct krb5int_dns_state **dsp,
            ? malloc(nextincr) : realloc(ds->ansp, nextincr);
 
        if (p == NULL && ds->ansp != NULL) {
-           free(ds->ansp);
-           return -1;
+           ret = -1;
+           goto errout;
        }
        ds->ansp = p;
        ds->ansmax = nextincr;
@@ -109,28 +110,45 @@ krb5int_dns_init(struct krb5int_dns_state **dsp,
        len = res_search(host, ds->nclass, ds->ntype,
                         ds->ansp, ds->ansmax);
 #endif
-       if (len > maxincr)
-           return -1;
+       if (len > maxincr) {
+           ret = -1;
+           goto errout;
+       }
        while (nextincr < len)
            nextincr *= 2;
        if (len < 0 || nextincr > maxincr) {
-           free(ds->ansp);
-           return -1;
+           ret = -1;
+           goto errout;
        }
     } while (len > ds->ansmax);
 
     ds->anslen = len;
 #if HAVE_NS_INITPARSE
-    len = ns_initparse(ds->ansp, ds->anslen, &ds->msg);
+    ret = ns_initparse(ds->ansp, ds->anslen, &ds->msg);
 #else
-    len = initparse(ds);
+    ret = initparse(ds);
 #endif
-    if (len < 0) {
-       free(ds->ansp);
-       return -1;
+    if (ret < 0)
+       goto errout;
+
+    ret = 0;
+
+errout:
+#if HAVE_RES_NSEARCH
+#if HAVE_RES_NDESTROY
+    res_ndestroy(&statbuf);
+#else
+    res_nclose(&statbuf);
+#endif
+#endif
+    if (ret < 0) {
+       if (ds->ansp != NULL) {
+           free(ds->ansp);
+           ds->ansp = NULL;
+       }
     }
 
-    return 0;
+    return ret;
 }
 
 #if HAVE_NS_INITPARSE
@@ -190,10 +208,11 @@ int krb5int_dns_expand(struct krb5int_dns_state *ds,
 void
 krb5int_dns_fini(struct krb5int_dns_state *ds)
 {
+    if (ds == NULL)
+       return;
     if (ds->ansp != NULL)
        free(ds->ansp);
-    if (ds != NULL)
-       free(ds);
+    free(ds);
 }
 
 /*