]> git.sur5r.net Git - openldap/commitdiff
memory leak fixes
authorJong Hyuk Choi <jongchoi@openldap.org>
Sat, 11 Sep 2004 02:02:09 +0000 (02:02 +0000)
committerJong Hyuk Choi <jongchoi@openldap.org>
Sat, 11 Sep 2004 02:02:09 +0000 (02:02 +0000)
13 files changed:
servers/slapd/add.c
servers/slapd/backend.c
servers/slapd/config.c
servers/slapd/init.c
servers/slapd/modify.c
servers/slapd/modrdn.c
servers/slapd/overlays/refint.c
servers/slapd/passwd.c
servers/slapd/proto-slap.h
servers/slapd/sasl.c
servers/slapd/slap.h
servers/slapd/slapi/slapi_ops.c
servers/slapd/syncrepl.c

index f3ad1d62c433dde74f3399aa9f723b69104608df..d4f6b6b914eb0457ab28027e8b5cf419af281110 100644 (file)
@@ -271,7 +271,7 @@ fe_op_add( Operation *op, SlapReply *rs )
                                        assert( (*modtail)->sml_desc != NULL );
                                }
                                rs->sr_err = slap_mods_opattrs( op, modlist, modtail,
-                                       &rs->sr_text, textbuf, textlen );
+                                       &rs->sr_text, textbuf, textlen, 1 );
                                if( rs->sr_err != LDAP_SUCCESS ) {
                                        send_ldap_result( op, rs );
                                        goto done;
index e01cc20ac85c928ef52a4c765a6724c4cee78d3c..349b7a621cc2cfed2cc86edf907581df80fa310f 100644 (file)
@@ -469,11 +469,19 @@ int backend_destroy(void)
 {
        int i;
        BackendDB *bd;
+       syncinfo_t *si_entry;
 
        ldap_pvt_thread_pool_destroy( &syncrepl_pool, 1 );
 
        /* destroy each backend database */
        for( i = 0, bd = backendDB; i < nBackendDB; i++, bd++ ) {
+
+               while ( !LDAP_STAILQ_EMPTY( &bd->be_syncinfo )) {
+                       si_entry = LDAP_STAILQ_FIRST( &bd->be_syncinfo );
+                       LDAP_STAILQ_REMOVE_HEAD( &bd->be_syncinfo, si_next );
+                       syncinfo_free( si_entry );
+               }
+               
                if ( bd->bd_info->bi_db_destroy ) {
                        bd->bd_info->bi_db_destroy( bd );
                }
index 3d85794ce81498627b1beb002b3fc70306645bf7..0db76d05ad30589533d1390250a8719b503df190 100644 (file)
@@ -2272,7 +2272,7 @@ add_syncrepl(
        }
        si->si_bindmethod = LDAP_AUTH_SIMPLE;
        si->si_schemachecking = 0;
-       ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 0,
+       ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 1,
                &si->si_filterstr );
        si->si_base.bv_val = NULL;
        si->si_scope = LDAP_SCOPE_SUBTREE;
@@ -2283,9 +2283,9 @@ add_syncrepl(
        si->si_exattrs[0] = NULL;
        si->si_type = LDAP_SYNC_REFRESH_ONLY;
        si->si_interval = 86400;
-       si->si_retryinterval = 0;
-       si->si_retrynum_init = 0;
-       si->si_retrynum = 0;
+       si->si_retryinterval = NULL;
+       si->si_retrynum_init = NULL;
+       si->si_retrynum = NULL;
        si->si_syncCookie.ctxcsn = NULL;
        si->si_syncCookie.octet_str = NULL;
        si->si_syncCookie.sid = -1;
@@ -2310,42 +2310,7 @@ add_syncrepl(
        }
 
        if ( rc < 0 || duplicated_replica_id ) {
-               syncinfo_t *si_entry;
-               /* Something bad happened - back out */
                Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
-
-               /* If error, remove all syncinfo */
-               LDAP_STAILQ_FOREACH( si_entry, &be->be_syncinfo, si_next ) {
-                       if ( si_entry->si_updatedn.bv_val ) {
-                               ch_free( si->si_updatedn.bv_val );
-                       }
-                       if ( si_entry->si_filterstr.bv_val ) {
-                               ch_free( si->si_filterstr.bv_val );
-                       }
-                       if ( si_entry->si_attrs ) {
-                               int i = 0;
-                               while ( si_entry->si_attrs[i] != NULL ) {
-                                       ch_free( si_entry->si_attrs[i] );
-                                       i++;
-                               }
-                               ch_free( si_entry->si_attrs );
-                       }
-                       if ( si_entry->si_exattrs ) {
-                               int i = 0;
-                               while ( si_entry->si_exattrs[i] != NULL ) {
-                                       ch_free( si_entry->si_exattrs[i] );
-                                       i++;
-                               }
-                               ch_free( si_entry->si_exattrs );
-                       }
-               }
-
-               while ( !LDAP_STAILQ_EMPTY( &be->be_syncinfo )) {
-                       si_entry = LDAP_STAILQ_FIRST( &be->be_syncinfo );
-                       LDAP_STAILQ_REMOVE_HEAD( &be->be_syncinfo, si_next );
-                       ch_free( si_entry );
-               }
-               LDAP_STAILQ_INIT( &be->be_syncinfo );
                return 1;
        } else {
                Debug( LDAP_DEBUG_CONFIG,
@@ -2435,7 +2400,7 @@ parse_syncrepl_line(
                        si->si_provideruri_bv = (BerVarray)
                                ch_calloc( 2, sizeof( struct berval ));
                        ber_str2bv( si->si_provideruri, strlen( si->si_provideruri ),
-                               0, &si->si_provideruri_bv[0] );
+                               1, &si->si_provideruri_bv[0] );
                        si->si_provideruri_bv[1].bv_len = 0;
                        si->si_provideruri_bv[1].bv_val = NULL;
                        gots |= GOT_PROVIDER;
@@ -2498,11 +2463,15 @@ parse_syncrepl_line(
                } else if ( !strncasecmp( cargv[ i ],
                                AUTHCSTR, sizeof( AUTHCSTR ) - 1 ) ) {
                        val = cargv[ i ] + sizeof( AUTHCSTR );
+                       if ( si->si_authcId )
+                               ch_free( si->si_authcId );
                        si->si_authcId = ch_strdup( val );
                } else if ( !strncasecmp( cargv[ i ],
                                OLDAUTHCSTR, sizeof( OLDAUTHCSTR ) - 1 ) ) {
                        /* Old authcID is provided for some backwards compatibility */
                        val = cargv[ i ] + sizeof( OLDAUTHCSTR );
+                       if ( si->si_authcId )
+                               ch_free( si->si_authcId );
                        si->si_authcId = ch_strdup( val );
                } else if ( !strncasecmp( cargv[ i ],
                                AUTHZSTR, sizeof( AUTHZSTR ) - 1 ) ) {
index 8ec751a958c1832f159db388725f2bfec6d905bd..40def39a95e2206e6d5b19bbb1f99a86e104e923 100644 (file)
@@ -222,7 +222,7 @@ int slap_destroy(void)
        int rc;
 
        Debug( LDAP_DEBUG_TRACE,
-               "%s shutdown: freeing system resources.\n",
+               "%s destroy: freeing system resources.\n",
                slap_name, 0, 0 );
 
 
index 908a4a841f1bc258326bd85ca54bd9b85509895c..1b707e175fce811be156a6d973f0436bc6a699ef 100644 (file)
@@ -427,7 +427,7 @@ fe_op_modify( Operation *op, SlapReply *rs )
                                }
 
                                rs->sr_err = slap_mods_opattrs( op, modlist, modtail,
-                                       &rs->sr_text, textbuf, textlen );
+                                       &rs->sr_text, textbuf, textlen, 1 );
                                if( rs->sr_err != LDAP_SUCCESS ) {
                                        send_ldap_result( op, rs );
                                        goto cleanup;
@@ -755,7 +755,8 @@ int slap_mods_opattrs(
        Modifications *mods,
        Modifications **modtail,
        const char **text,
-       char *textbuf, size_t textlen )
+       char *textbuf, size_t textlen,
+       int manage_ctxcsn )
 {
        struct berval name, timestamp, csn;
        struct berval nname;
@@ -784,7 +785,7 @@ int slap_mods_opattrs(
 #endif /* HAVE_GMTIME_R */
                lutil_gentime( timebuf, sizeof(timebuf), ltm );
 
-               slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, 1 );
+               slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, manage_ctxcsn );
 
 #ifndef HAVE_GMTIME_R
                ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
index db5a99f680d9b7a2dbe50e912e6c389e1f849929..f5c8a33bf012060cba8a0e6cfa8201cbc5b8fff0 100644 (file)
@@ -536,7 +536,8 @@ done:
                        /* empty */
                }
 
-               rs->sr_err = slap_mods_opattrs( op, mod, modtail, &rs->sr_text, textbuf, textlen );
+               rs->sr_err = slap_mods_opattrs( op, mod, modtail,
+                                               &rs->sr_text, textbuf, textlen, 1 );
        }
 
        /* LDAP v2 supporting correct attribute handling. */
index fb8f229324b30a16da3d87912a078348d3061506..987ffc32046753f6c93dd7734dcef5388a957bd5 100644 (file)
@@ -631,7 +631,7 @@ refint_response(
                nop.o_dn = refint_dn;
                nop.o_ndn = refint_dn;
                rs->sr_err = slap_mods_opattrs( &nop, nop.orm_modlist,
-                       tail, &rs->sr_text, NULL, 0 );
+                       tail, &rs->sr_text, NULL, 0, 1 );
                nop.o_dn = nop.o_bd->be_rootdn;
                nop.o_ndn = nop.o_bd->be_rootndn;
                if(rs->sr_err != LDAP_SUCCESS) goto done;
index 6832098f956275ef0b3912d315bf31cda01f8c58..89247b54f8ac90c6547b28f14b7de25566fa1369 100644 (file)
@@ -210,7 +210,7 @@ int passwd_extop(
                                         * if it cares... */
 
                rs->sr_err = slap_mods_opattrs( &op2, ml, qpw->rs_modtail, &rs->sr_text,
-                       NULL, 0 );
+                       NULL, 0, 1 );
                
                if ( rs->sr_err == LDAP_SUCCESS ) {
                        rs->sr_err = op2.o_bd->be_modify( &op2, rs );
index f6e78692bc8ca09e63747b571bb4f6dfd9deb08d..c5b71729ce800d672c1e3b6828042fed826105fb 100644 (file)
@@ -755,7 +755,8 @@ LDAP_SLAPD_F( int ) slap_mods_opattrs(
        Modifications *mods,
        Modifications **modlist,
        const char **text,
-       char *textbuf, size_t textlen );
+       char *textbuf, size_t textlen,
+       int manage_ctxcsn );
 
 /*
  * mods.c
@@ -1225,6 +1226,7 @@ LDAP_SLAPD_F (struct berval *) slap_uuidstr_from_normalized LDAP_P((
                                        struct berval *, struct berval *, void * ));
 LDAP_SLAPD_F (int) syncrepl_isupdate LDAP_P(( Operation * ));
 LDAP_SLAPD_F (int) syncrepl_isupdate_dn LDAP_P(( Backend *, struct berval * ));
+LDAP_SLAPD_F (void) syncinfo_free LDAP_P(( syncinfo_t * ));
 
 /* syntax.c */
 LDAP_SLAPD_F (Syntax *) syn_find LDAP_P((
index 44313a51a869f395ce0d296c6a4b7280b1cf45e9..f00d0ab6b875373aa1fc683a0640465d63737f79 100644 (file)
@@ -502,7 +502,7 @@ slap_auxprop_store(
 
        if ( rc == LDAP_SUCCESS ) {
                rc = slap_mods_opattrs( &op, modlist, modtail, &text, textbuf,
-                       textlen );
+                       textlen, 1 );
        }
 
        if ( rc == LDAP_SUCCESS ) {
index 10804f08a521d1e421959b36272a54449e5c2d29..9fa5fc22e60c3ddfa07794516bebf2d125c20dbf 100644 (file)
@@ -1435,7 +1435,6 @@ typedef struct syncinfo_s {
         char                           *si_authcId;
         char                           *si_authzId;
                int                                     si_schemachecking;
-        Filter                         *si_filter;
         struct berval          si_filterstr;
         struct berval          si_base;
         int                                    si_scope;
index 1a3aa220532dbc034bdbb3dbf449eb814182657a..c8e978380300b5fc1139e78deb5e7b70c02ca0bb 100644 (file)
@@ -463,7 +463,7 @@ slapi_int_ldapmod_to_entry(
                        if ( !repl_user ) {
                                rc = slap_mods_opattrs( op,
                                                modlist, modtail, &text, 
-                                               textbuf, textlen );
+                                               textbuf, textlen, 1 );
                                if ( rc != LDAP_SUCCESS) {
                                        goto cleanup;
                                }
@@ -1029,7 +1029,7 @@ slapi_modify_internal(
                        if ( !repl_user ) {
                                rs.sr_err = slap_mods_opattrs( op, modlist,
                                                modtail, &text, textbuf, 
-                                               textlen );
+                                               textlen, 1 );
                                if ( rs.sr_err != LDAP_SUCCESS ) {
                                        goto cleanup;
                                }
index 895f11c8cad8d03aee4a947fe163f7c78259e984..cb39b532c813baf648c8296793da0d7dcbc082d8 100644 (file)
@@ -407,6 +407,8 @@ done:
                }
        }
 
+       slap_sl_free( op->o_req_ndn.bv_val, op->o_tmpmemctx );
+
        return rc;
 }
 
@@ -664,11 +666,12 @@ do_syncrep2(
                                                for ( i = 0; syncUUIDs[i].bv_val; i++ ) {
                                                        struct berval *syncuuid_bv;
                                                        syncuuid_bv = ber_dupbv( NULL, &syncUUIDs[i] );
+                                                       slap_sl_free( syncUUIDs[i].bv_val,op->o_tmpmemctx );
                                                        avl_insert( &si->si_presentlist,
                                                                (caddr_t) syncuuid_bv,
                                                                syncuuid_cmp, avl_dup_error );
                                                }
-                                               ber_memfree_x( syncUUIDs, op->o_tmpmemctx );
+                                               slap_sl_free( syncUUIDs, op->o_tmpmemctx );
                                                break;
                                        default:
                                        Debug( LDAP_DEBUG_ANY,
@@ -747,9 +750,6 @@ done:
        slap_sync_cookie_free( &syncCookie, 0 );
        slap_sync_cookie_free( &syncCookie_req, 0 );
 
-       avl_free( si->si_presentlist, avl_ber_bvfree );
-       si->si_presentlist = NULL;
-
        if ( res ) ldap_msgfree( res );
 
        if ( rc && si->si_ld ) {
@@ -832,8 +832,7 @@ do_syncrepl(
                         */
                        if ( rc == LDAP_SUCCESS ) {
                                if ( first ) {
-                                       rc = connection_client_setup( s, do_syncrepl,
-                                               arg );
+                                       rc = connection_client_setup( s, do_syncrepl, arg );
                                } else {
                                        connection_client_enable( s );
                                } 
@@ -1274,10 +1273,10 @@ syncrepl_entry(
 done :
 
        if ( syncUUID_strrep.bv_val ) {
-               ber_memfree_x( syncUUID_strrep.bv_val, op->o_tmpmemctx );
+               slap_sl_free( syncUUID_strrep.bv_val, op->o_tmpmemctx );
        }
        if ( si->si_syncUUID_ndn.bv_val ) {
-               ber_memfree_x( si->si_syncUUID_ndn.bv_val, op->o_tmpmemctx );
+               ch_free( si->si_syncUUID_ndn.bv_val );
        }
        return ret;
 }
@@ -1664,7 +1663,7 @@ syncrepl_updateCookie(
 
        op->o_tag = LDAP_REQ_ADD;
        rc = slap_mods_opattrs( op, modlist, modtail,
-                &text, txtbuf, textlen );
+                &text, txtbuf, textlen, 0 );
 
        for ( ml = modlist; ml != NULL; ml = ml->sml_next ) {
                ml->sml_op = LDAP_MOD_REPLACE;
@@ -1807,7 +1806,7 @@ dn_callback(
                        Debug( LDAP_DEBUG_ANY,
                                "dn_callback : consistency error - entryUUID is not unique\n", 0, 0, 0 );
                } else {
-                       ber_dupbv_x( &si->si_syncUUID_ndn, &rs->sr_entry->e_nname, op->o_tmpmemctx );
+                       ber_dupbv_x( &si->si_syncUUID_ndn, &rs->sr_entry->e_nname, NULL );
                }
        } else if ( rs->sr_type == REP_RESULT ) {
                if ( rs->sr_err == LDAP_SIZELIMIT_EXCEEDED ) {
@@ -1982,3 +1981,98 @@ avl_ber_bvfree( void *bv )
        }
        ch_free( (char *) bv );
 }
+
+void
+syncinfo_free( syncinfo_t *sie )
+{
+       if ( sie->si_provideruri ) {
+               ch_free( sie->si_provideruri );
+       }
+       if ( sie->si_provideruri_bv ) {
+               ber_bvarray_free( sie->si_provideruri_bv );
+       }
+       if ( sie->si_updatedn.bv_val ) {
+               ch_free( sie->si_updatedn.bv_val );
+       }
+       if ( sie->si_binddn ) {
+               ch_free( sie->si_binddn );
+       }
+       if ( sie->si_passwd ) {
+               ch_free( sie->si_passwd );
+       }
+       if ( sie->si_saslmech ) {
+               ch_free( sie->si_saslmech );
+       }
+       if ( sie->si_secprops ) {
+               ch_free( sie->si_secprops );
+       }
+       if ( sie->si_realm ) {
+               ch_free( sie->si_realm );
+       }
+       if ( sie->si_authcId ) {
+               ch_free( sie->si_authcId );
+       }
+       if ( sie->si_authzId ) {
+               ch_free( sie->si_authzId );
+       }
+       if ( sie->si_filterstr.bv_val ) {
+               ch_free( sie->si_filterstr.bv_val );
+       }
+       if ( sie->si_base.bv_val ) {
+               ch_free( sie->si_base.bv_val );
+       }
+       if ( sie->si_attrs ) {
+               int i = 0;
+               while ( sie->si_attrs[i] != NULL ) {
+                       ch_free( sie->si_attrs[i] );
+                       i++;
+               }
+               ch_free( sie->si_attrs );
+       }
+       if ( sie->si_exattrs ) {
+               int i = 0;
+               while ( sie->si_exattrs[i] != NULL ) {
+                       ch_free( sie->si_exattrs[i] );
+                       i++;
+               }
+               ch_free( sie->si_exattrs );
+       }
+       if ( sie->si_retryinterval ) {
+               ch_free( sie->si_retryinterval );
+       }
+       if ( sie->si_retrynum ) {
+               ch_free( sie->si_retrynum );
+       }
+       if ( sie->si_retrynum_init ) {
+               ch_free( sie->si_retrynum_init );
+       }
+       slap_sync_cookie_free( &sie->si_syncCookie, 0 );
+       if ( sie->si_syncUUID_ndn.bv_val ) {
+               ch_free( sie->si_syncUUID_ndn.bv_val );
+       }
+       if ( sie->si_presentlist ) {
+           avl_free( sie->si_presentlist, avl_ber_bvfree );
+       }
+       if ( sie->si_ld ) {
+               ldap_ld_free( sie->si_ld, 1, NULL, NULL );
+       }
+       while ( !LDAP_LIST_EMPTY( &sie->si_nonpresentlist )) {
+               struct nonpresent_entry* npe;
+               npe = LDAP_LIST_FIRST( &sie->si_nonpresentlist );
+               LDAP_LIST_REMOVE( npe, npe_link );
+               if ( npe->npe_name ) {
+                       if ( npe->npe_name->bv_val ) {
+                               ch_free( npe->npe_name->bv_val );
+                       }
+                       ch_free( npe->npe_name );
+               }
+               if ( npe->npe_nname ) {
+                       if ( npe->npe_nname->bv_val ) {
+                               ch_free( npe->npe_nname->bv_val );
+                       }
+                       ch_free( npe->npe_nname );
+               }
+               ch_free( npe );
+       }
+       ch_free( sie );
+}