]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#9952 libldap: use atexit for TLS teardown
authorHoward Chu <hyc@openldap.org>
Fri, 19 May 2023 15:37:14 +0000 (16:37 +0100)
committerQuanah Gibson-Mount <quanah@openldap.org>
Tue, 26 Sep 2023 17:23:05 +0000 (17:23 +0000)
libraries/libldap/init.c
libraries/libldap/tls2.c

index 3a81790dcf86b0005ef1f6a087e102bf8dd79a7d..b9915533bd92129af5c9a5bd787a4a47fe1ecbeb 100644 (file)
@@ -544,9 +544,6 @@ ldap_int_destroy_global_options(void)
                gopts->ldo_def_sasl_authcid = NULL;
        }
 #endif
-#ifdef HAVE_TLS
-       ldap_int_tls_destroy( gopts );
-#endif
 }
 
 /* 
index 4a5d42b297238b8fbda54edd19887681e7f3ebc4..f9dcbfc8d7d33b56a2a7c21209d5a67477d8b0fb 100644 (file)
@@ -160,6 +160,14 @@ ldap_pvt_tls_destroy( void )
        tls_imp->ti_tls_destroy();
 }
 
+static void
+ldap_exit_tls_destroy( void )
+{
+       struct ldapoptions *lo = LDAP_INT_GLOBAL_OPT();
+
+       ldap_int_tls_destroy( lo );
+}
+
 /*
  * Initialize a particular TLS implementation.
  * Called once per implementation.
@@ -168,6 +176,7 @@ static int
 tls_init(tls_impl *impl, int do_threads )
 {
        static int tls_initialized = 0;
+       int rc;
 
        if ( !tls_initialized++ ) {
 #ifdef LDAP_R_COMPILE
@@ -183,7 +192,10 @@ tls_init(tls_impl *impl, int do_threads )
 #endif
        }
 
-       return impl->ti_tls_init();
+       rc = impl->ti_tls_init();
+
+       atexit( ldap_exit_tls_destroy );
+       return rc;
 }
 
 /*