]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#9907 Plug shutdown related leaks in lloadd
authorOndřej Kuzník <ondra@mistotebe.net>
Tue, 30 Aug 2022 12:25:18 +0000 (13:25 +0100)
committerQuanah Gibson-Mount <quanah@openldap.org>
Mon, 12 Sep 2022 20:42:44 +0000 (20:42 +0000)
servers/lloadd/config.c
servers/lloadd/daemon.c
servers/lloadd/extended.c
servers/lloadd/init.c
servers/lloadd/main.c
servers/lloadd/module_init.c
servers/lloadd/proto-lload.h

index cabef479c64ae41802e794a0a5f87693ee612a2a..1d64c58d5a7f6e1dace6d46f83af71bceb417df6 100644 (file)
@@ -1319,14 +1319,15 @@ config_bindconf( ConfigArgs *c )
     }
 
     if ( !BER_BVISNULL( &bindconf.sb_authzId ) ) {
-        ber_dupbv( &lloadd_identity, &bindconf.sb_authzId );
+        ber_bvreplace( &lloadd_identity, &bindconf.sb_authzId );
     } else if ( !BER_BVISNULL( &bindconf.sb_authcId ) ) {
-        ber_dupbv( &lloadd_identity, &bindconf.sb_authcId );
+        ber_bvreplace( &lloadd_identity, &bindconf.sb_authcId );
     } else if ( !BER_BVISNULL( &bindconf.sb_binddn ) ) {
         char *ptr;
 
         lloadd_identity.bv_len = STRLENOF("dn:") + bindconf.sb_binddn.bv_len;
-        lloadd_identity.bv_val = ch_malloc( lloadd_identity.bv_len + 1 );
+        lloadd_identity.bv_val = ch_realloc(
+                lloadd_identity.bv_val, lloadd_identity.bv_len + 1 );
 
         ptr = lutil_strcopy( lloadd_identity.bv_val, "dn:" );
         ptr = lutil_strncopy(
@@ -1552,10 +1553,12 @@ config_tier( ConfigArgs *c )
     if ( CONFIG_ONLINE_ADD( c ) ) {
         assert( tier );
         lload_change.target = tier;
+        ch_free( c->value_string );
         return rc;
     }
 
     tier_impl = lload_tier_find( c->value_string );
+    ch_free( c->value_string );
     if ( !tier_impl ) {
         goto fail;
     }
index bd571324948f0c2bec1bd96984c060b226fa6cf5..53b1810db56209d3addde4f89014cdd9bf89c6a7 100644 (file)
@@ -780,6 +780,9 @@ lloadd_daemon_destroy( void )
             }
         }
 
+        event_free( lload_stats_event );
+        event_free( lload_timeout_event );
+
         event_base_free( daemon_base );
         daemon_base = NULL;
 
index 8b72454aa7bce080a7ba03579cdfc2cdeca197a0..c49623e85a4f1918d0eb5aa154a05fa6dbbbaf44 100644 (file)
@@ -211,3 +211,10 @@ lload_exop_init( void )
 
     return LDAP_SUCCESS;
 }
+
+void
+lload_exop_destroy( void )
+{
+    ldap_avl_free( lload_exop_handlers, NULL );
+    lload_exop_handlers = NULL;
+}
index a304226faaef1389539b19cad7909e414d282a1e..fe1c1ae5f4a8f25c2d7df0cc6111d09b1e2ce917 100644 (file)
@@ -107,6 +107,37 @@ lload_global_init( void )
     return 0;
 }
 
+int
+lload_global_destroy( void )
+{
+    if ( !BER_BVISNULL( &lloadd_identity ) ) {
+        ch_free( lloadd_identity.bv_val );
+        BER_BVZERO( &lloadd_identity );
+    }
+
+    lload_exop_destroy();
+
+#ifdef HAVE_TLS
+    if ( lload_tls_backend_ld ) {
+        ldap_unbind_ext( lload_tls_backend_ld, NULL, NULL );
+    }
+    if ( lload_tls_ld ) {
+        ldap_unbind_ext( lload_tls_ld, NULL, NULL );
+    }
+#endif
+
+    ldap_pvt_thread_mutex_destroy( &lload_wait_mutex );
+    ldap_pvt_thread_cond_destroy( &lload_wait_cond );
+    ldap_pvt_thread_cond_destroy( &lload_pause_cond );
+
+    ldap_pvt_thread_mutex_destroy( &clients_mutex );
+    ldap_pvt_thread_mutex_destroy( &lload_pin_mutex );
+
+    lload_libevent_destroy();
+
+    return 0;
+}
+
 int
 lload_tls_init( void )
 {
index 4b7225ae90d081ac6413abee0185779daed38ac3..1c76ef3536543c3b4c0bba24f9774fd7911e64b6 100644 (file)
@@ -870,6 +870,7 @@ destroy:
         (void)loglevel_print( stdout );
     }
     /* remember an error during destroy */
+    rc |= lload_global_destroy();
     rc |= lload_destroy();
 
 stop:
index 1475538cecdcb15049a744a6c9b3733e6bdb5f9c..19323c73132ffa4f38ed40fdb2cc383cf6afcda8 100644 (file)
@@ -140,6 +140,12 @@ lload_back_close( BackendInfo *bi )
     return 0;
 }
 
+int
+lload_back_destroy( BackendInfo *bi )
+{
+    return lload_global_destroy();
+}
+
 int
 lload_back_initialize( BackendInfo *bi )
 {
@@ -149,7 +155,7 @@ lload_back_initialize( BackendInfo *bi )
     bi->bi_pause = lload_pause_cb;
     bi->bi_unpause = lload_unpause_cb;
     bi->bi_close = lload_back_close;
-    bi->bi_destroy = 0;
+    bi->bi_destroy = lload_back_destroy;
 
     bi->bi_db_init = 0;
     bi->bi_db_config = 0;
index b73fe8818ebe5ada2a9a1ef99278f00c9b0605d3..f69111e17892e202defebacf62aa280f59981311 100644 (file)
@@ -143,11 +143,13 @@ LDAP_SLAPD_V (Avlnode *) lload_exop_handlers;
 LDAP_SLAPD_F (int) exop_handler_cmp( const void *l, const void *r );
 LDAP_SLAPD_F (int) request_extended( LloadConnection *c, LloadOperation *op );
 LDAP_SLAPD_F (int) lload_exop_init( void );
+LDAP_SLAPD_F (void) lload_exop_destroy( void );
 
 /*
  * init.c
  */
 LDAP_SLAPD_F (int) lload_global_init( void );
+LDAP_SLAPD_F (int) lload_global_destroy( void );
 LDAP_SLAPD_F (int) lload_tls_init( void );
 LDAP_SLAPD_F (int) lload_init( int mode, const char *name );
 LDAP_SLAPD_F (int) lload_destroy( void );