From: Ken Raeburn Date: Wed, 9 Feb 2005 00:41:40 +0000 (+0000) Subject: There is a memory leak here, if a thread has registered some per-thread data X-Git-Tag: ms-bug-test-20060525~343 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=36f1eda337a7fbbdb53fd0b2c92e2f32085aca78;p=thirdparty%2Fkrb5.git There is a memory leak here, if a thread has registered some per-thread data when we delete the key. Fixing it will require walking through the per-thread data of every thread and freeing the objects... and watching for deadlocks in the case where a thread is exiting at the same time. * threads.c (k5_key_delete) [pthread case]: Reset flags and destructor function pointer to unset state. (krb5int_thread_support_init, krb5int_thread_support_fini): If SHOW_INITFINI_FUNCS is defined, print some tracing messages. ticket: 2916 status: open git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@17092 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/util/support/ChangeLog b/src/util/support/ChangeLog index a39bb1ff38..4686f935b5 100644 --- a/src/util/support/ChangeLog +++ b/src/util/support/ChangeLog @@ -1,3 +1,10 @@ +2005-02-08 Ken Raeburn + + * threads.c (k5_key_delete) [pthread case]: Reset flags and + destructor function pointer to unset state. + (krb5int_thread_support_init, krb5int_thread_support_fini): If + SHOW_INITFINI_FUNCS is defined, print some tracing messages. + 2005-01-18 Ken Raeburn * threads.c (k5_key_delete) [ENABLE_THREADS && !_WIN32]: Don't diff --git a/src/util/support/threads.c b/src/util/support/threads.c index bef4264aa6..51ad788143 100644 --- a/src/util/support/threads.c +++ b/src/util/support/threads.c @@ -312,8 +312,21 @@ int k5_key_delete (k5_key_t keynum) #else /* POSIX */ - /* Not written yet -- resource leak! */ - /* abort(); */ + { + int err; + + /* XXX RESOURCE LEAK: + + Need to destroy the allocated objects first! */ + + err = k5_mutex_lock(&key_lock); + if (err == 0) { + assert(destructors_set[keynum] == 1); + destructors_set[keynum] = 0; + destructors[keynum] = NULL; + k5_mutex_unlock(&key_lock); + } + } #endif @@ -336,6 +349,10 @@ int krb5int_thread_support_init (void) { int err; +#ifdef SHOW_INITFINI_FUNCS + printf("krb5int_thread_support_init\n"); +#endif + #ifdef DEBUG_THREADS_STATS /* stats_logfile = stderr; */ stats_logfile = fopen("/dev/tty", "w+"); @@ -378,6 +395,10 @@ void krb5int_thread_support_fini (void) if (! INITIALIZER_RAN (krb5int_thread_support_init)) return; +#ifdef SHOW_INITFINI_FUNCS + printf("krb5int_thread_support_fini\n"); +#endif + #ifndef ENABLE_THREADS /* Do nothing. */