From: Tom Yu Date: Sat, 15 Jan 2005 00:10:53 +0000 (+0000) Subject: pullup from trunk X-Git-Tag: krb5-1.4.3-beta1~104 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=06fa16c16258b95db4954a32e6a38166973d2b8d;p=krb5.git pullup from trunk ticket: 2872 version_fixed: 1.4 git-svn-id: svn://anonsvn.mit.edu/krb5/branches/krb5-1-4@17042 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/ChangeLog b/src/ChangeLog index 0094190e1..e053ae05d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2005-01-12 Tom Yu + + * aclocal.m4 (AC_LIBRARY_NET): Also check for res_ndestroy. + 2004-12-16 Ezra Peisach * krb5-config.in: Add krb5support library. diff --git a/src/aclocal.m4 b/src/aclocal.m4 index 595e41dd4..d135d5c10 100644 --- a/src/aclocal.m4 +++ b/src/aclocal.m4 @@ -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. diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index 00b7cb835..469bdacf3 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,3 +1,10 @@ +2005-01-12 Tom Yu + + * 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 * thread_safe.c: (new file) krb5_is_thread_safe() diff --git a/src/lib/krb5/os/dnsglue.c b/src/lib/krb5/os/dnsglue.c index dba1b869c..5d2db3695 100644 --- a/src/lib/krb5/os/dnsglue.c +++ b/src/lib/krb5/os/dnsglue.c @@ -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); } /*