From f7de358516d442bd8cb8e9afb880ddeb51922bf5 Mon Sep 17 00:00:00 2001 From: Ezra Peisach Date: Fri, 3 Jan 2003 16:28:45 +0000 Subject: [PATCH] * main.c: On exit, free more allocated memory, including: realm_tcp_ports data, kdc_realmlist, close the replay cache, and free the lookaside cache. * network.c (FREE_SET_DATA): Do not free a NULL pointer. * replay.c, kdc_util.h: Add kdc_free_lookaside() to clear the lookaside cache on shutdown - to search for memory leaks. * rtest.c (main): Do not allocate or free a NULL pointer. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@15080 dc483132-0cff-0310-8789-dd5450dbe970 --- src/kdc/ChangeLog | 13 +++++++++++++ src/kdc/kdc_util.h | 1 + src/kdc/main.c | 15 ++++++++++++++- src/kdc/network.c | 3 ++- src/kdc/replay.c | 19 +++++++++++++++++++ src/kdc/rtest.c | 8 ++++++-- 6 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/kdc/ChangeLog b/src/kdc/ChangeLog index 4f771c656..0e58dece8 100644 --- a/src/kdc/ChangeLog +++ b/src/kdc/ChangeLog @@ -1,3 +1,16 @@ +2003-01-03 Ezra Peisach + + * main.c: On exit, free more allocated memory, including: + realm_tcp_ports data, kdc_realmlist, close the replay cache, and + free the lookaside cache. + + * network.c (FREE_SET_DATA): Do not free a NULL pointer. + + * replay.c, kdc_util.h: Add kdc_free_lookaside() to clear the lookaside + cache on shutdown - to search for memory leaks. + + * rtest.c (main): Do not allocate or free a NULL pointer. + 2002-12-30 Ken Raeburn * kerberos_v4.c (process_v4): Use a temporary variable for the diff --git a/src/kdc/kdc_util.h b/src/kdc/kdc_util.h index 8e48932e4..11a916078 100644 --- a/src/kdc/kdc_util.h +++ b/src/kdc/kdc_util.h @@ -158,6 +158,7 @@ krb5_boolean kdc_check_lookaside (krb5_data *, const krb5_fulladdr *, krb5_data **); void kdc_insert_lookaside (krb5_data *, const krb5_fulladdr *, krb5_data *); +void kdc_free_lookaside(void); /* sock2p.c */ extern void sockaddr2p (const struct sockaddr *, char *, size_t, int *); diff --git a/src/kdc/main.c b/src/kdc/main.c index 67be4751a..c338b53a8 100644 --- a/src/kdc/main.c +++ b/src/kdc/main.c @@ -119,6 +119,8 @@ finish_realm(kdc_realm_t *rdp) free(rdp->realm_stash); if (rdp->realm_ports) free(rdp->realm_ports); + if (rdp->realm_tcp_ports) + free(rdp->realm_tcp_ports); if (rdp->realm_kstypes) free(rdp->realm_kstypes); if (rdp->realm_keytab) @@ -140,6 +142,7 @@ finish_realm(kdc_realm_t *rdp) krb5_free_context(rdp->realm_context); } memset((char *) rdp, 0, sizeof(*rdp)); + free(rdp); } /* @@ -737,8 +740,10 @@ finish_realms(char *prog) { int i; - for (i = 0; i < kdc_numrealms; i++) + for (i = 0; i < kdc_numrealms; i++) { finish_realm(kdc_realmlist[i]); + kdc_realmlist[i] = 0; + } } /* @@ -837,6 +842,14 @@ int main(int argc, char **argv) krb5_klog_syslog(LOG_INFO, "shutting down"); krb5_klog_close(kdc_context); finish_realms(argv[0]); + if (kdc_realmlist) + free(kdc_realmlist); +#ifdef USE_RCACHE + (void) krb5_rc_close(kdc_context, kdc_rcache); +#endif +#ifndef NOCACHE + kdc_free_lookaside(); +#endif krb5_free_context(kcontext); return errout; } diff --git a/src/kdc/network.c b/src/kdc/network.c index 56edc4078..4c49102a9 100644 --- a/src/kdc/network.c +++ b/src/kdc/network.c @@ -205,7 +205,8 @@ struct connection { #define DEL(set, idx) \ (set.data[idx] = set.data[--set.n], 0) -#define FREE_SET_DATA(set) (free(set.data), set.data = 0, set.max = 0) +#define FREE_SET_DATA(set) if(set.data) free(set.data); \ + (set.data = 0, set.max = 0) /* Set connections; */ diff --git a/src/kdc/replay.c b/src/kdc/replay.c index 8bb79abfa..18210b8c1 100644 --- a/src/kdc/replay.c +++ b/src/kdc/replay.c @@ -168,4 +168,23 @@ kdc_insert_lookaside(krb5_data *inpkt, const krb5_fulladdr *from, return; } +/* frees memory associated with the lookaside queue for memory profiling */ +void +kdc_free_lookaside() +{ + register krb5_kdc_replay_ent *eptr, *last, *hold; + if (root_ptr.next) { + for (last = &root_ptr, eptr = root_ptr.next; + eptr; eptr = eptr->next) { + krb5_free_data(kdc_context, eptr->req_packet); + krb5_free_data(kdc_context, eptr->reply_packet); + krb5_free_address(kdc_context, eptr->addr); + hold = eptr; + last->next = eptr->next; + eptr = last; + free(hold); + } + } +} + #endif /* NOCACHE */ diff --git a/src/kdc/rtest.c b/src/kdc/rtest.c index 1ae78a176..d63e92fcf 100644 --- a/src/kdc/rtest.c +++ b/src/kdc/rtest.c @@ -85,7 +85,10 @@ main(int argc, char **argv) ntrans.data = 0; otrans.length = strlen(argv[1]); - otrans.data = (char *) malloc(otrans.length); + if (otrans.length) + otrans.data = (char *) malloc(otrans.length); + else + otrans.data = 0; memcpy(otrans.data,argv[1], otrans.length); tgs = make_princ(kdc_context, argv[2], argv[0]); @@ -97,7 +100,8 @@ main(int argc, char **argv) printf("%s\n",ntrans.data); /* Free up all memory so we can profile for leaks */ - free(otrans.data); + if (otrans.data) + free(otrans.data); free(ntrans.data); krb5_free_principal(kdc_realm.realm_context, tgs); -- 2.26.2