Blame SOURCES/krb5-1.12-nodelete-plugins.patch

4be148
commit 0f46175d632ae03ab7d4cfba5e62534d31e128e0
4be148
Author: Greg Hudson <ghudson@mit.edu>
4be148
Date:   Wed Jun 25 11:41:54 2014 -0400
4be148
4be148
    Load plugins with RTLD_NODELETE if possible
4be148
    
4be148
    On platforms which support RTLD_NODELETE, use it to load plugin
4be148
    modules.  While using this flag makes plugins stay in the process map
4be148
    after libkrb5/libgssapi_krb5 are unloaded, it solves several problems:
4be148
    
4be148
    1. It prevents plugin modules which link against OpenSSL (PKINIT and
4be148
    k5tls) from repeatedly initializing instances of libssl or libcrypto,
4be148
    leaking heap memory each time.  This is only an issue because we
4be148
    cannot safely uninitialize OpenSSL.
4be148
    
4be148
    2. It prevents finalization ordering issues from causing a process
4be148
    crash when unloading libgssapi_krb5 (issue #7135).
4be148
    
4be148
    3. It makes memory leak tracing with valgrind easier.
4be148
    
4be148
    ticket: 7947 (new)
4be148
4be148
diff --git a/src/util/support/plugins.c b/src/util/support/plugins.c
4be148
index a04dfc3..ca4b128 100644
4be148
--- a/src/util/support/plugins.c
4be148
+++ b/src/util/support/plugins.c
4be148
@@ -45,6 +45,20 @@
4be148
 
4be148
 #include "k5-platform.h"
4be148
 
4be148
+#if USE_DLOPEN
4be148
+#ifdef RTLD_GROUP
4be148
+#define GROUP RTLD_GROUP
4be148
+#else
4be148
+#define GROUP 0
4be148
+#endif
4be148
+#ifdef RTLD_NODELETE
4be148
+#define NODELETE RTLD_NODELETE
4be148
+#else
4be148
+#define NODELETE 0
4be148
+#endif
4be148
+#define PLUGIN_DLOPEN_FLAGS (RTLD_NOW | RTLD_LOCAL | GROUP | NODELETE)
4be148
+#endif
4be148
+
4be148
 #if USE_DLOPEN && USE_CFBUNDLE
4be148
 #include <CoreFoundation/CoreFoundation.h>
4be148
 
4be148
@@ -257,11 +271,6 @@ krb5int_open_plugin (const char *filepath, struct plugin_file_handle **h, struct
4be148
         }
4be148
 #endif /* USE_CFBUNDLE */
4be148
 
4be148
-#ifdef RTLD_GROUP
4be148
-#define PLUGIN_DLOPEN_FLAGS (RTLD_NOW | RTLD_LOCAL | RTLD_GROUP)
4be148
-#else
4be148
-#define PLUGIN_DLOPEN_FLAGS (RTLD_NOW | RTLD_LOCAL)
4be148
-#endif
4be148
         if (!err) {
4be148
             handle = dlopen(filepath, PLUGIN_DLOPEN_FLAGS);
4be148
             if (handle == NULL) {