Imported Upstream version 1.20.1
[platform/upstream/krb5.git] / src / util / support / plugins.c
index 47368be..c6a9a21 100644 (file)
 #define PLUGIN_DLOPEN_FLAGS (RTLD_NOW | RTLD_LOCAL | GROUP | NODELETE)
 #endif
 
+/*
+ * glibc bug 11941, fixed in release 2.25, can cause an assertion failure in
+ * dlclose() on process exit.  Our workaround is to leak dlopen() handles
+ * (which doesn't typically manifest in leak detection tools because the
+ * handles are still reachable via a global table in libdl).  Because we
+ * dlopen() with RTLD_NODELETE, we weren't going to unload the plugin objects
+ * anyway.
+ */
+#ifdef __GLIBC_PREREQ
+#if ! __GLIBC_PREREQ(2, 25)
+#define dlclose(x)
+#endif
+#endif
+
 #if USE_DLOPEN && USE_CFBUNDLE
 #include <CoreFoundation/CoreFoundation.h>
 
@@ -175,9 +189,10 @@ long KRB5_CALLCONV
 krb5int_open_plugin (const char *filepath, struct plugin_file_handle **h, struct errinfo *ep)
 {
     long err = 0;
-    struct stat statbuf;
     struct plugin_file_handle *htmp = NULL;
     int got_plugin = 0;
+#if defined(USE_CFBUNDLE) || defined(_WIN32)
+    struct stat statbuf;
 
     if (!err) {
         if (stat (filepath, &statbuf) < 0) {
@@ -187,6 +202,7 @@ krb5int_open_plugin (const char *filepath, struct plugin_file_handle **h, struct
                          filepath, strerror(err));
         }
     }
+#endif
 
     if (!err) {
         htmp = calloc (1, sizeof (*htmp)); /* calloc initializes ptrs to NULL */
@@ -194,11 +210,12 @@ krb5int_open_plugin (const char *filepath, struct plugin_file_handle **h, struct
     }
 
 #if USE_DLOPEN
-    if (!err && ((statbuf.st_mode & S_IFMT) == S_IFREG
+    if (!err
 #if USE_CFBUNDLE
-                 || (statbuf.st_mode & S_IFMT) == S_IFDIR
+                 && ((statbuf.st_mode & S_IFMT) == S_IFREG
+                 || (statbuf.st_mode & S_IFMT) == S_IFDIR)
 #endif /* USE_CFBUNDLE */
-        )) {
+        ) {
         void *handle = NULL;
 
 #if USE_CFBUNDLE