From 63ec3a4b97a3b00ea34d6a9f84d4b7b34383a645 Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Thu, 23 Jun 2011 19:26:01 +0000 Subject: [PATCH] Fix a minor memory leak in kadmin kadmin_getprinc() was using the variable "canon" for two purposes. After r22785, canon wasn't freed between constructions, so the first value was leaked. Fix by using separate variables for separate strings. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@24987 dc483132-0cff-0310-8789-dd5450dbe970 --- src/kadmin/cli/kadmin.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/kadmin/cli/kadmin.c b/src/kadmin/cli/kadmin.c index 4935141ef..9e8eef333 100644 --- a/src/kadmin/cli/kadmin.c +++ b/src/kadmin/cli/kadmin.c @@ -1428,7 +1428,7 @@ kadmin_getprinc(int argc, char *argv[]) kadm5_principal_ent_rec dprinc; krb5_principal princ = NULL; krb5_error_code retval; - char *canon = NULL, *modcanon = NULL; + char *canon = NULL, *princstr = NULL, *modprincstr = NULL; int i; size_t j; @@ -1455,18 +1455,18 @@ kadmin_getprinc(int argc, char *argv[]) com_err("get_principal", retval, _("while retrieving \"%s\"."), canon); goto cleanup; } - retval = krb5_unparse_name(context, dprinc.principal, &canon); + retval = krb5_unparse_name(context, dprinc.principal, &princstr); if (retval) { - com_err("get_principal", retval, _("while canonicalizing principal")); + com_err("get_principal", retval, _("while unparsing principal")); goto cleanup; } - retval = krb5_unparse_name(context, dprinc.mod_name, &modcanon); + retval = krb5_unparse_name(context, dprinc.mod_name, &modprincstr); if (retval) { - com_err("get_principal", retval, _("while unparsing modname")); + com_err("get_principal", retval, _("while unparsing principal")); goto cleanup; } if (argc == 2) { - printf(_("Principal: %s\n"), canon); + printf(_("Principal: %s\n"), princstr); printf(_("Expiration date: %s\n"), dprinc.princ_expire_time ? strdate(dprinc.princ_expire_time) : _("[never]")); printf(_("Last password change: %s\n"), dprinc.last_pwd_change ? @@ -1478,7 +1478,7 @@ kadmin_getprinc(int argc, char *argv[]) printf(_("Maximum renewable life: %s\n"), strdur(dprinc.max_renewable_life)); printf(_("Last modified: %s (%s)\n"), strdate(dprinc.mod_date), - modcanon); + modprincstr); printf(_("Last successful authentication: %s\n"), dprinc.last_success ? strdate(dprinc.last_success) : _("[never]")); @@ -1518,8 +1518,8 @@ kadmin_getprinc(int argc, char *argv[]) } else { printf("\"%s\"\t%d\t%d\t%d\t%d\t\"%s\"\t%d\t%d\t%d\t%d\t\"%s\"" "\t%d\t%d\t%d\t%d\t%d", - canon, dprinc.princ_expire_time, dprinc.last_pwd_change, - dprinc.pw_expiration, dprinc.max_life, modcanon, + princstr, dprinc.princ_expire_time, dprinc.last_pwd_change, + dprinc.pw_expiration, dprinc.max_life, modprincstr, dprinc.mod_date, dprinc.attributes, dprinc.kvno, dprinc.mkvno, dprinc.policy ? dprinc.policy : "[none]", dprinc.max_renewable_life, dprinc.last_success, @@ -1536,8 +1536,9 @@ kadmin_getprinc(int argc, char *argv[]) cleanup: krb5_free_principal(context, princ); kadm5_free_principal_ent(handle, &dprinc); - free(modcanon); free(canon); + free(princstr); + free(modprincstr); } void -- 2.26.2