There is a memory leak here, if a thread has registered some per-thread data
authorKen Raeburn <raeburn@mit.edu>
Wed, 9 Feb 2005 00:41:40 +0000 (00:41 +0000)
committerKen Raeburn <raeburn@mit.edu>
Wed, 9 Feb 2005 00:41:40 +0000 (00:41 +0000)
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

src/util/support/ChangeLog
src/util/support/threads.c

index a39bb1ff3883c91fd3e71579d07de5389f6a559c..4686f935b50d3b15af4b88ba46846ac266941b15 100644 (file)
@@ -1,3 +1,10 @@
+2005-02-08  Ken Raeburn  <raeburn@mit.edu>
+
+       * 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  <raeburn@mit.edu>
 
        * threads.c (k5_key_delete) [ENABLE_THREADS && !_WIN32]: Don't
index bef4264aa61c6d44a9323fc74cc87a8e84aed8dc..51ad788143dbf975e1d1ac803e5b94c0b009a351 100644 (file)
@@ -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.  */