From: Tom Yu Date: Mon, 3 Mar 2003 07:49:34 +0000 (+0000) Subject: * g_cnffile.c (krb__get_srvtabname): Keep strdup()ed string in a X-Git-Tag: krb5-1.3-alpha1~62 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=99e30b57804a04e1d7f47e14e7392745aa997527;p=krb5.git * g_cnffile.c (krb__get_srvtabname): Keep strdup()ed string in a static variable and free it called again; this prevents a memory leak. ticket: 1357 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@15215 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb4/ChangeLog b/src/lib/krb4/ChangeLog index 6ae5f55eb..bd31edc55 100644 --- a/src/lib/krb4/ChangeLog +++ b/src/lib/krb4/ChangeLog @@ -1,3 +1,9 @@ +2003-03-03 Tom Yu + + * g_cnffile.c (krb__get_srvtabname): Keep strdup()ed string in a + static variable and free it called again; this prevents a memory + leak. + 2003-02-28 Ezra Peisach * Makefile.in (clean-unix): Remove krb_err_txt.c on clean. Update diff --git a/src/lib/krb4/g_cnffile.c b/src/lib/krb4/g_cnffile.c index c31a9d219..8d61f5056 100644 --- a/src/lib/krb4/g_cnffile.c +++ b/src/lib/krb4/g_cnffile.c @@ -56,7 +56,7 @@ krb__get_srvtabname(default_srvtabname) const char* names[3]; char **full_name = 0, **cpp; krb5_error_code retval; - char *retname; + static char *retname; if (!krb5__krb4_context) krb5_init_context(&krb5__krb4_context); @@ -67,6 +67,8 @@ krb__get_srvtabname(default_srvtabname) retval = profile_get_values(krb5__krb4_context->profile, names, &full_name); if (retval == 0 && full_name && full_name[0]) { + if (retname != NULL) + free(retname); retname = strdup(full_name[0]); for (cpp = full_name; *cpp; cpp++) krb5_xfree(*cpp); @@ -74,6 +76,8 @@ krb__get_srvtabname(default_srvtabname) return retname; } } + if (retname != NULL) + free(retname); retname = strdup(default_srvtabname); return retname; }