From 1a9ab00e34a847c185c7c8bb3ae4ecf68890e3b7 Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Thu, 2 Jun 1994 16:46:56 +0000 Subject: [PATCH] Clean up memory allocation strategy in replay cache git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@3676 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/rcache/rc_dfl.c | 54 ++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/src/lib/krb5/rcache/rc_dfl.c b/src/lib/krb5/rcache/rc_dfl.c index 87c4a1b71..0c012b7a8 100644 --- a/src/lib/krb5/rcache/rc_dfl.c +++ b/src/lib/krb5/rcache/rc_dfl.c @@ -207,6 +207,8 @@ krb5_rcache id; struct authlist *q; FREE(t->h); + if (t->name) + FREE(t->name); while (q = t->a) { t->a = q->na; @@ -244,25 +246,43 @@ krb5_error_code krb5_rc_dfl_resolve(id, name) krb5_rcache id; char *name; { - struct dfl_data *t; - int i; - - /* allocate id? no */ - if (!(t = (struct dfl_data *) malloc(sizeof(struct dfl_data)))) - return KRB5_RC_MALLOC; - id->data = (krb5_pointer) t; - t->name = name; /* gee, difficult... */ - t->numhits = t->nummisses = 0; - t->hsize = HASHSIZE; /* no need to store---it's memory-only */ - if (!(t->h = (struct authlist **) malloc(t->hsize*sizeof(struct authlist *)))) - return KRB5_RC_MALLOC; - for (i = 0;i < t->hsize;i++) - t->h[i] = (struct authlist *) 0; - t->a = (struct authlist *) 0; + struct dfl_data *t = 0; + krb5_error_code retval; + + /* allocate id? no */ + if (!(t = (struct dfl_data *) malloc(sizeof(struct dfl_data)))) + return KRB5_RC_MALLOC; + id->data = (krb5_pointer) t; + memset(t, 0, sizeof(struct dfl_data)); + t->name = malloc(strlen(name)+1); + if (!t->name) { + retval = KRB5_RC_MALLOC; + goto cleanup; + } + strcpy(t->name, name); + t->numhits = t->nummisses = 0; + t->hsize = HASHSIZE; /* no need to store---it's memory-only */ + t->h = (struct authlist **) malloc(t->hsize*sizeof(struct authlist *)); + if (!t->h) { + retval = KRB5_RC_MALLOC; + goto cleanup; + } + memset(t->h, 0, t->hsize*sizeof(struct authlist *)); + t->a = (struct authlist *) 0; #ifndef NOIOSTUFF - t->d.fd = -1; + t->d.fd = -1; #endif - return 0; + return 0; + +cleanup: + if (t) { + if (t->name) + krb5_xfree(t->name); + if (t->h) + krb5_xfree(t->h); + krb5_xfree(t); + } + return retval; } void krb5_rc_free_entry (rep) -- 2.26.2