]> git.sur5r.net Git - openldap/commitdiff
don't leak callbacks if stuff cannot be registered; provide a means to dispose of...
authorPierangelo Masarati <ando@openldap.org>
Sun, 24 Dec 2006 15:44:56 +0000 (15:44 +0000)
committerPierangelo Masarati <ando@openldap.org>
Sun, 24 Dec 2006 15:44:56 +0000 (15:44 +0000)
servers/slapd/back-bdb/monitor.c
servers/slapd/back-ldap/monitor.c
servers/slapd/back-monitor/back-monitor.h
servers/slapd/back-monitor/cache.c
servers/slapd/back-monitor/init.c

index 73497963814cbe36b27f2da7f6afc97845a6a0fb..e0693f4914f79c4b403692ff2da380a07402f492 100644 (file)
@@ -152,6 +152,7 @@ bdb_monitor_update(
        return SLAP_CB_CONTINUE;
 }
 
+#if 0  /* uncomment if required */
 static int
 bdb_monitor_modify(
        Operation       *op,
@@ -161,11 +162,12 @@ bdb_monitor_modify(
 {
        return SLAP_CB_CONTINUE;
 }
+#endif
 
 static int
 bdb_monitor_free(
        Entry           *e,
-       void            *priv )
+       void            **priv )
 {
        struct berval   values[ 2 ];
        Modification    mod = { 0 };
@@ -176,6 +178,7 @@ bdb_monitor_free(
        int             i, rc;
 
        /* NOTE: if slap_shutdown != 0, priv might have already been freed */
+       *priv = NULL;
 
        /* Remove objectClass */
        mod.sm_op = LDAP_MOD_DELETE;
index 288ff6a440bf23d0a69f444c7fd46d30fe5101f4..b621807f022873ec7ec0702870c10eea9a9a646d 100644 (file)
@@ -265,9 +265,11 @@ done:;
 static int
 ldap_back_monitor_free(
        Entry           *e,
-       void            *priv )
+       void            **priv )
 {
-       ldapinfo_t              *li = (ldapinfo_t *)priv;
+       ldapinfo_t              *li = (ldapinfo_t *)(*priv);
+
+       *priv = NULL;
 
        if ( !slapd_shutdown && !BER_BVISNULL( &li->li_monitor_info.lmi_rdn ) ) {
                ldap_back_monitor_info_destroy( li );
@@ -306,7 +308,6 @@ static int
 ldap_back_monitor_initialize( void )
 {
        int             i, code;
-       const char      *err;
        ConfigArgs c;
        char    *argv[ 3 ];
 
index 905bcf73ff651a6619cfbecbb37caca23cdc8078..3c8e742b8f381a50fbe9199510783d0a4c6bb77a 100644 (file)
@@ -39,9 +39,13 @@ typedef struct monitor_callback_t {
        int                             (*mc_modify)( Operation *op, SlapReply *rs, Entry *e, void *priv );
                                                /* modify callback
                                                   for user-defined entries */
-       int                             (*mc_free)( Entry *e, void *priv );
+       int                             (*mc_free)( Entry *e, void **priv );
                                                /* delete callback
                                                   for user-defined entries */
+       void                            (*mc_dispose)( void **priv );
+                                               /* dispose callback
+                                                  to dispose of the callback
+                                                  private data itself */
        void                            *mc_private;    /* opaque pointer to
                                                   private data */
        struct monitor_callback_t       *mc_next;
index 9c96c0c154adaa7b1515f38f04ca17b8a5f69ac2..5f198080bb46949ef77c5ad10b71418ffe17185b 100644 (file)
@@ -405,7 +405,7 @@ monitor_entry_destroy( void *v_mc )
                                monitor_callback_t      *next = cb->mc_next;
 
                                if ( cb->mc_free ) {
-                                       cb->mc_free( mc->mc_e, cb->mc_private );
+                                       (void)cb->mc_free( mc->mc_e, &cb->mc_private );
                                }
                                ch_free( mp->mp_cb );
 
index 4b32e124b00957590720412c2845bb5449f5e7b6..388488b2ed509159ad43651d4a3295481f36815a 100644 (file)
@@ -992,7 +992,6 @@ done:;
                        return -1;
                }
 
-done_limbo:;
                if ( *elpp != NULL ) {
                        el.el_next = NULL;
                        **elpp = el;
@@ -1080,7 +1079,7 @@ monitor_back_unregister_entry(
                        monitor_callback_t      *next = cb->mc_next;
 
                        if ( cb->mc_free ) {
-                               (void)cb->mc_free( e, cb->mc_private );
+                               (void)cb->mc_free( e, &cb->mc_private );
                        }
                        ch_free( cb );
 
@@ -1208,7 +1207,7 @@ monitor_back_unregister_entry_parent(
                        for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
                                if ( *cbp == target_cb ) {
                                        if ( (*cbp)->mc_free ) {
-                                               (void)(*cbp)->mc_free( e, (*cbp)->mc_private );
+                                               (void)(*cbp)->mc_free( e, &(*cbp)->mc_private );
                                        }
                                        *cbp = (*cbp)->mc_next;
                                        ch_free( target_cb );
@@ -1370,7 +1369,7 @@ monitor_back_unregister_entry_attrs(
                        for ( cbp = &mp->mp_cb; *cbp != NULL; cbp = &(*cbp)->mc_next ) {
                                if ( *cbp == target_cb ) {
                                        if ( (*cbp)->mc_free ) {
-                                               (void)(*cbp)->mc_free( e, (*cbp)->mc_private );
+                                               (void)(*cbp)->mc_free( e, &(*cbp)->mc_private );
                                        }
                                        *cbp = (*cbp)->mc_next;
                                        ch_free( target_cb );
@@ -1837,7 +1836,6 @@ monitor_back_initialize(
        };
 
        int                     i, rc;
-       const char              *text;
        monitor_info_t          *mi = &monitor_info;
        ConfigArgs c;
        char    *argv[ 3 ];
@@ -2231,10 +2229,11 @@ monitor_back_db_open(
 
                for ( ; el; ) {
                        entry_limbo_t   *tmp;
+                       int             rc;
 
                        switch ( el->el_type ) {
                        case LIMBO_ENTRY:
-                               monitor_back_register_entry(
+                               rc = monitor_back_register_entry(
                                                el->el_e,
                                                el->el_cb,
                                                el->el_mss,
@@ -2242,7 +2241,7 @@ monitor_back_db_open(
                                break;
 
                        case LIMBO_ENTRY_PARENT:
-                               monitor_back_register_entry_parent(
+                               rc = monitor_back_register_entry_parent(
                                                el->el_e,
                                                el->el_cb,
                                                el->el_mss,
@@ -2254,7 +2253,7 @@ monitor_back_db_open(
                                
 
                        case LIMBO_ATTRS:
-                               monitor_back_register_entry_attrs(
+                               rc = monitor_back_register_entry_attrs(
                                                &el->el_ndn,
                                                el->el_a,
                                                el->el_cb,
@@ -2264,7 +2263,7 @@ monitor_back_db_open(
                                break;
 
                        case LIMBO_CB:
-                               monitor_back_register_entry_callback(
+                               rc = monitor_back_register_entry_callback(
                                                &el->el_ndn,
                                                el->el_cb,
                                                &el->el_nbase,
@@ -2291,6 +2290,12 @@ monitor_back_db_open(
                        if ( !BER_BVISNULL( &el->el_filter ) ) {
                                ber_memfree( el->el_filter.bv_val );
                        }
+                       if ( el->el_cb && rc != 0 ) {
+                               if ( el->el_cb->mc_dispose ) {
+                                       el->el_cb->mc_dispose( &el->el_cb->mc_private );
+                               }
+                               ch_free( el->el_cb );
+                       }
 
                        tmp = el;
                        el = el->el_next;