]> git.sur5r.net Git - openldap/commitdiff
syncrepl memleak fix
authorKurt Zeilenga <kurt@openldap.org>
Sun, 12 Sep 2004 22:22:38 +0000 (22:22 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Sun, 12 Sep 2004 22:22:38 +0000 (22:22 +0000)
16 files changed:
CHANGES
build/version.var
doc/man/man5/ldif.5
servers/slapd/add.c
servers/slapd/back-sql/backsql.dsp [deleted file]
servers/slapd/backend.c
servers/slapd/config.c
servers/slapd/dn.c
servers/slapd/modify.c
servers/slapd/modrdn.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

diff --git a/CHANGES b/CHANGES
index 92e4fd323223834cafccd54be04a43d028091a81..097844e5ebbba95ab62cf54c8b86bfa1567a858c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,10 @@
 OpenLDAP 2.2 Change Log
 
+OpenLDAP 2.2.17 Engineering
+       Fixed slapd syncrepl memory leak bugs
+       Documentation
+               Updated ldif(5)
+
 OpenLDAP 2.2.16 Release
        Fixed libldap getaddrinfo hints portability bug (ITS#3279)
        Fixed libldap find_connection bug (ITS#3280)
index e27a32eb439f359be9595a47660f9cde2fd808d3..5901b3bbc826ee8043cc83aaf427dc280585330d 100644 (file)
@@ -15,7 +15,7 @@
 ol_package=OpenLDAP
 ol_major=2
 ol_minor=2
-ol_patch=16
+ol_patch=X
 ol_api_inc=20216
 ol_api_current=7
 ol_api_revision=9
index fe65b44957664012f5f0b562081f4d750d4d7749..2ba94843795f658cef8d84c4dddc07faa195b991 100644 (file)
@@ -82,7 +82,7 @@ Here is an example of an LDIF file containing three entries.
     cn: Barbara J Jensen
     cn: Babs Jensen
     objectclass: person
-    description:< file://tmp/babs
+    description:< file:///tmp/babs
     sn: Jensen
 
     dn: cn=Bjorn J Jensen,dc=example,dc=com
@@ -104,7 +104,7 @@ Here is an example of an LDIF file containing three entries.
 .fi
 .LP
 Notice that the description in Barbara Jensen's entry is
-read from file://tmp/babs and the jpegPhoto in Jennifer
+read from file:///tmp/babs and the jpegPhoto in Jennifer
 Jensen's entry is encoded using base 64.
 .SH SEE ALSO
 .BR ldap (3),
index db2b0743ba93db6ac0d8ed50b2fc490472477be6..f0035c5d3e037e7a14a8ba0ed80a3ec9f75c5659 100644 (file)
@@ -279,7 +279,7 @@ do_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;
diff --git a/servers/slapd/back-sql/backsql.dsp b/servers/slapd/back-sql/backsql.dsp
deleted file mode 100644 (file)
index 8a5189e..0000000
+++ /dev/null
@@ -1,205 +0,0 @@
-# Microsoft Developer Studio Project File - Name="backsql" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 5.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Static Library" 0x0104
-
-CFG=backsql - Win32 Single Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE 
-!MESSAGE NMAKE /f "backsql.mak".
-!MESSAGE 
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE 
-!MESSAGE NMAKE /f "backsql.mak" CFG="backsql - Win32 Single Debug"
-!MESSAGE 
-!MESSAGE Possible choices for configuration are:
-!MESSAGE 
-!MESSAGE "backsql - Win32 Release" (based on "Win32 (x86) Static Library")
-!MESSAGE "backsql - Win32 Debug" (based on "Win32 (x86) Static Library")
-!MESSAGE "backsql - Win32 Single Debug" (based on "Win32 (x86) Static Library")
-!MESSAGE "backsql - Win32 Single Release" (based on\
- "Win32 (x86) Static Library")
-!MESSAGE 
-
-# Begin Project
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-
-!IF  "$(CFG)" == "backsql - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "..\..\..\Release"
-# PROP Intermediate_Dir "..\..\..\Release\backsql"
-# PROP Target_Dir ""
-RSC=rc.exe
-# ADD BASE RSC /l 0x419
-# ADD RSC /l 0x419
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
-# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\\" /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo
-
-!ELSEIF  "$(CFG)" == "backsql - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "..\..\..\Debug"
-# PROP Intermediate_Dir "..\..\..\Debug\backsql"
-# PROP Target_Dir ""
-RSC=rc.exe
-# ADD BASE RSC /l 0x419
-# ADD RSC /l 0x419
-# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
-# ADD CPP /nologo /MTd /W3 /GX /Z7 /Od /I "..\\" /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX /FD /c
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo
-
-!ELSEIF  "$(CFG)" == "backsql - Win32 Single Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "backsql"
-# PROP BASE Intermediate_Dir "backsql"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "..\..\..\SDebug"
-# PROP Intermediate_Dir "..\..\..\SDebug\backsql"
-# PROP Target_Dir ""
-RSC=rc.exe
-# ADD BASE RSC /l 0x419
-# ADD RSC /l 0x419
-# ADD BASE CPP /nologo /MTd /W3 /GX /Z7 /Od /I "..\\" /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX /FD /c
-# ADD CPP /nologo /W3 /GX /Z7 /Od /I "..\\" /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR /YX /FD /c
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo
-
-!ELSEIF  "$(CFG)" == "backsql - Win32 Single Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "backldb0"
-# PROP BASE Intermediate_Dir "backldb0"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "..\..\..\SRelease"
-# PROP Intermediate_Dir "..\..\..\SRelease\backsql"
-# PROP Target_Dir ""
-RSC=rc.exe
-# ADD BASE RSC /l 0x419
-# ADD RSC /l 0x419
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\\" /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
-# ADD CPP /nologo /W3 /GX /O2 /I "..\\" /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo
-
-!ENDIF 
-
-# Begin Target
-
-# Name "backsql - Win32 Release"
-# Name "backsql - Win32 Debug"
-# Name "backsql - Win32 Single Debug"
-# Name "backsql - Win32 Single Release"
-# Begin Source File
-
-SOURCE=".\back-sql.h"
-# End Source File
-# Begin Source File
-
-SOURCE=.\bind.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\config.c
-# End Source File
-# Begin Source File
-
-SOURCE=".\entry-id.c"
-# End Source File
-# Begin Source File
-
-SOURCE=".\entry-id.h"
-# End Source File
-# Begin Source File
-
-SOURCE=.\external.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\init.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\modify.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\other.c
-# End Source File
-# Begin Source File
-
-SOURCE=".\schema-map.c"
-# End Source File
-# Begin Source File
-
-SOURCE=".\schema-map.h"
-# End Source File
-# Begin Source File
-
-SOURCE=.\search.c
-# End Source File
-# Begin Source File
-
-SOURCE=".\sql-types.h"
-# End Source File
-# Begin Source File
-
-SOURCE=".\sql-wrap.c"
-# End Source File
-# Begin Source File
-
-SOURCE=".\sql-wrap.h"
-# End Source File
-# Begin Source File
-
-SOURCE=.\util.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\util.h
-# End Source File
-# End Target
-# End Project
index 823436a33a24a71f3c83421ed9421bbee3b9572c..79923821be4f2a61aa9c57fd59fafe63ea73a80b 100644 (file)
@@ -520,11 +520,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 354c1a902c4aef82f69604050c84e18f6d9d8832..c12b4c5188c26bb74422b49c852de4be5f5678a4 100644 (file)
@@ -2952,7 +2952,7 @@ add_syncrepl(
        }
        si->si_bindmethod = LDAP_AUTH_SIMPLE;
        si->si_schemachecking = 0;
-       ber_str2bv( "(objectclass=*)", sizeof("(objectclass=*)")-1, 0,
+       ber_str2bv( "(objectclass=*)", STRLENOF("(objectclass=*)"), 1,
                &si->si_filterstr );
        si->si_base.bv_val = NULL;
        si->si_scope = LDAP_SCOPE_SUBTREE;
@@ -2963,9 +2963,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;
@@ -2995,46 +2995,7 @@ add_syncrepl(
        }
 
        if ( rc < 0 || duplicated_replica_id ) {
-               syncinfo_t *si_entry;
-               /* Something bad happened - back out */
-#ifdef NEW_LOGGING
-               LDAP_LOG( CONFIG, ERR, "failed to add syncinfo\n", 0, 0,0 );
-#else
                Debug( LDAP_DEBUG_ANY, "failed to add syncinfo\n", 0, 0, 0 );
-#endif
-
-               /* 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 {
 #ifdef NEW_LOGGING
@@ -3130,7 +3091,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;
@@ -3193,11 +3154,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 f00cfacdc20aab47ac18e38ad5259e7e22d246f1..1c59250ea4d82dcb1a922a0d4fb149dac830637e 100644 (file)
@@ -700,6 +700,33 @@ dnParent(
        return;
 }
 
+/*
+ * dnRdn - dn's rdn, in-place
+ * note: the incoming dn is assumed to be normalized/prettyfied,
+ * so that escaped rdn/ava separators are in '\'+hexpair form
+ */
+void
+dnRdn( 
+       struct berval   *dn, 
+       struct berval   *rdn )
+{
+       char    *p;
+
+       *rdn = *dn;
+       p = strchr( dn->bv_val, ',' );
+
+       /* one-level dn */
+       if ( p == NULL ) {
+               return;
+       }
+
+       assert( DN_SEPARATOR( p[ 0 ] ) );
+       assert( ATTR_LEADCHAR( p[ 1 ] ) );
+       rdn->bv_len = p - dn->bv_val;
+
+       return;
+}
+
 int
 dnExtractRdn( 
        struct berval   *dn, 
index d4856338600d49d59c439f8c673dfab01a72903b..584cfb0660ded1f6e8511bb7f7764a48ef5b8ce6 100644 (file)
@@ -487,7 +487,7 @@ do_modify(
                                }
 
                                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;
@@ -830,7 +830,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;
@@ -859,7 +860,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 3e76ad1e758e6883cffd1caacbea9c5f43505df9..938a7734cb1b7bfb6aac072742399e66fa4bc756 100644 (file)
@@ -630,7 +630,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 25d541d8957470d76f017ee8c2970d9885fe6b26..6e933ca40183861701aa9b32c12baa6ab4e60147 100644 (file)
@@ -199,7 +199,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 fba64839c164dd49890e1d0cf6d7cef40e0c04e1..216f37098ebec1eab236c1c6801bfb4dceb770e3 100644 (file)
@@ -481,6 +481,7 @@ LDAP_SLAPD_F (void) build_new_dn LDAP_P((
        void *memctx ));
 
 LDAP_SLAPD_F (void) dnParent LDAP_P(( struct berval *dn, struct berval *pdn ));
+LDAP_SLAPD_F (void) dnRdn LDAP_P(( struct berval *dn, struct berval *rdn ));
 
 LDAP_SLAPD_F (int) dnX509normalize LDAP_P(( void *x509_name, struct berval *out ));
 
@@ -693,7 +694,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
@@ -1145,6 +1147,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 388f90231dfc664a4ac7c9384403d2d3b7c4e6cf..b10b0ffa92400c47cfb6d45fb1581cda6cef8ec4 100644 (file)
@@ -569,7 +569,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 8ecdc581c7ddaf9610cc036504eeb69ee1c6c6f1..8cc4dc9fee0b78c785c77ff8efcd94c2b697e679 100644 (file)
@@ -1390,7 +1390,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 f3e6ecb4be41bee84682187839631b966342e594..ec352c190d8f0992d8f43999c744fc00bed1c75a 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 cc6496293a5a5b41084a1b638f48c24a8ac9ad30..dd856562168c000639a616b0d5fef4a52fd22a33 100644 (file)
@@ -448,6 +448,8 @@ done:
                }
        }
 
+       slap_sl_free( op->o_req_ndn.bv_val, op->o_tmpmemctx );
+
        return rc;
 }
 
@@ -703,11 +705,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:
 #ifdef NEW_LOGGING
@@ -805,9 +808,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,6 +832,7 @@ do_syncrepl(
        int dostop = 0;
        ber_socket_t s;
        int i, defer = 1;
+       Backend *be;
 
 #ifdef NEW_LOGGING
        LDAP_LOG ( OPERATION, DETAIL1, "do_syncrepl\n", 0, 0, 0 );
@@ -867,7 +868,7 @@ do_syncrepl(
        op.o_dn = si->si_updatedn;
        op.o_ndn = si->si_updatedn;
        op.o_managedsait = 1;
-       op.o_bd = si->si_be;
+       op.o_bd = be = si->si_be;
 
        op.o_sync_state.ctxcsn = NULL;
        op.o_sync_state.sid = -1;
@@ -894,8 +895,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 );
                                } 
@@ -943,6 +943,8 @@ do_syncrepl(
 
                if ( !si->si_retrynum || si->si_retrynum[i] == -2 ) {
                        ldap_pvt_runqueue_remove( &syncrepl_rq, rtask );
+                       LDAP_STAILQ_REMOVE( &be->be_syncinfo, si, syncinfo_s, si_next );
+                       syncinfo_free( si );
                } else if ( si->si_retrynum[i] >= -1 ) {
                        if ( si->si_retrynum[i] > 0 )
                                si->si_retrynum[i]--;
@@ -1383,10 +1385,11 @@ 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 );
+               si->si_syncUUID_ndn.bv_val = NULL;
        }
        return ret;
 }
@@ -1771,7 +1774,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;
@@ -1947,7 +1950,7 @@ dn_callback(
                                "dn_callback : consistency error - entryUUID is not unique\n", 0, 0, 0 );
 #endif
                } 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 ) {
@@ -2142,3 +2145,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 );
+}