+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.
# 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.
+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()
struct __res_state statbuf;
#endif
struct krb5int_dns_state *ds;
- int len;
+ int len, ret;
size_t nextincr, maxincr;
unsigned char *p;
if (ds == NULL)
return -1;
+ ret = -1;
ds->nclass = nclass;
ds->ntype = ntype;
ds->ansp = NULL;
#endif
#if HAVE_RES_NSEARCH
- len = res_ninit(&statbuf);
- if (len < 0)
+ ret = res_ninit(&statbuf);
+ if (ret < 0)
return -1;
#endif
? 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;
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
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);
}
/*