]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#8039 Free resinfo even if opcookie is the last owner
authorOndřej Kuzník <ondra@mistotebe.net>
Thu, 13 Jan 2022 09:21:21 +0000 (09:21 +0000)
committerQuanah Gibson-Mount <quanah@openldap.org>
Tue, 18 Jan 2022 23:07:47 +0000 (23:07 +0000)
servers/slapd/overlays/syncprov.c

index 60ea91e450d77909459dad87afd49088fd4b90da..364ee8ada07e7f5246e94382d7ee6f33c0ed3f48 100644 (file)
@@ -843,24 +843,27 @@ again:
 static void free_resinfo( syncres *sr )
 {
        syncres **st;
+       resinfo *ri = sr->s_info;
        int freeit = 0;
-       ldap_pvt_thread_mutex_lock( &sr->s_info->ri_mutex );
+
+       ldap_pvt_thread_mutex_lock( &ri->ri_mutex );
        for (st = &sr->s_info->ri_list; *st; st = &(*st)->s_rilist) {
                if (*st == sr) {
                        *st = sr->s_rilist;
+                       if ( !sr->s_info->ri_list )
+                               freeit = 1;
+                       sr->s_info = NULL;
                        break;
                }
        }
-       if ( !sr->s_info->ri_list )
-               freeit = 1;
-       ldap_pvt_thread_mutex_unlock( &sr->s_info->ri_mutex );
+       ldap_pvt_thread_mutex_unlock( &ri->ri_mutex );
        if ( freeit ) {
-               ldap_pvt_thread_mutex_destroy( &sr->s_info->ri_mutex );
-               if ( sr->s_info->ri_e )
-                       entry_free( sr->s_info->ri_e );
-               if ( !BER_BVISNULL( &sr->s_info->ri_cookie ))
-                       ch_free( sr->s_info->ri_cookie.bv_val );
-               ch_free( sr->s_info );
+               ldap_pvt_thread_mutex_destroy( &ri->ri_mutex );
+               if ( ri->ri_e )
+                       entry_free( ri->ri_e );
+               if ( !BER_BVISNULL( &ri->ri_cookie ))
+                       ch_free( ri->ri_cookie.bv_val );
+               ch_free( ri );
        }
 }
 
@@ -1546,6 +1549,10 @@ syncprov_op_cleanup( Operation *op, SlapReply *rs )
        if ( !BER_BVISNULL( &opc->sdn ))
                op->o_tmpfree( opc->sdn.bv_val, op->o_tmpmemctx );
        op->o_callback = cb->sc_next;
+
+       if ( opc->ssres.s_info ) {
+               free_resinfo( &opc->ssres );
+       }
        op->o_tmpfree(cb, op->o_tmpmemctx);
 
        return 0;