if ( text ) ldap_memfree( text );
        if ( matched ) ldap_memfree( matched );
-       if ( text ) ber_memvfree( (void **)refs );
+       if ( refs ) ber_memvfree( (void **)refs );
 
        if ( ctrls ) {
                tool_print_ctrls( ld, ctrls );
 
 
        entry_clean( &rdi->rdi_e );
 
+       if ( !BER_BVISNULL( &rdi->rdi_unsolicited_oid ) ) {
+               ber_memfree( rdi->rdi_unsolicited_oid.bv_val );
+               if ( !BER_BVISNULL( &rdi->rdi_unsolicited_data ) )
+                       ber_memfree( rdi->rdi_unsolicited_data.bv_val );
+       }
+
        ch_free( rdi );
 }
 
 
 
        rc = rewrite_parse( si->si_rewrite, c->fname, c->lineno, 4, argvRule );
        ch_free( vnc );
+       ch_free( rnc );
        return rc;
 }
 #endif
 
        fprintf( stderr, "  PID=%ld - Modrdn done (%d).\n", (long) pid, rc );
 
        ldap_unbind_ext( ld, NULL, NULL );
-}
-
 
+       free( DNs[1] );
+       free( rdns[0] );
+       free( rdns[1] );
+}