summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorTheodore Tso <tytso@mit.edu>1994-06-02 16:46:56 +0000
committerTheodore Tso <tytso@mit.edu>1994-06-02 16:46:56 +0000
commit1a9ab00e34a847c185c7c8bb3ae4ecf68890e3b7 (patch)
tree70d2f2c106144e4e0fe70173e772331c9bfbd825 /src/lib
parent95bed1c8a53fb1e11468c235ce75e8224fa22bb4 (diff)
Clean up memory allocation strategy in replay cache
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@3676 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/krb5/rcache/rc_dfl.c54
1 files 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)