ldap_memfree(air);
 
-                               if ( rc ) {
+                               while ( names > sat->sat_names ) {
                                        struct aindexrec        tmpair;
 
-                                       while ( names > sat->sat_names ) {
-                                               names--;
-                                               ber_str2bv( *names, 0, 0, &tmpair.air_name );
-                                               tmpair.air_at = sat;
-                                               air = avl_delete( &attr_index,
-                                                       (caddr_t)&tmpair, attr_index_cmp );
-                                               assert( air != NULL );
-                                               ldap_memfree( air );
-                                       }
-
-                                       if ( sat->sat_oid ) {
-                                               ber_str2bv( sat->sat_oid, 0, 0, &tmpair.air_name );
-                                               tmpair.air_at = sat;
-                                               air = avl_delete( &attr_index,
-                                                       (caddr_t)&tmpair, attr_index_cmp );
-                                               assert( air != NULL );
-                                               ldap_memfree( air );
-                                       }
+                                       names--;
+                                       ber_str2bv( *names, 0, 0, &tmpair.air_name );
+                                       tmpair.air_at = sat;
+                                       air = (struct aindexrec *)avl_delete( &attr_index,
+                                               (caddr_t)&tmpair, attr_index_cmp );
+                                       assert( air != NULL );
+                                       ldap_memfree( air );
+                               }
+
+                               if ( sat->sat_oid ) {
+                                       struct aindexrec        tmpair;
+
+                                       ber_str2bv( sat->sat_oid, 0, 0, &tmpair.air_name );
+                                       tmpair.air_at = sat;
+                                       air = (struct aindexrec *)avl_delete( &attr_index,
+                                               (caddr_t)&tmpair, attr_index_cmp );
+                                       assert( air != NULL );
+                                       ldap_memfree( air );
                                }
 
                                return rc;
 
                                rc = oc_check_dup( old_soc, soc );
 
                                ldap_memfree( oir );
+
+                               while ( names > soc->soc_names ) {
+                                       struct oindexrec        tmpoir;
+
+                                       names--;
+                                       ber_str2bv( *names, 0, 0, &tmpoir.oir_name );
+                                       tmpoir.oir_oc = soc;
+                                       oir = (struct oindexrec *)avl_delete( &oc_index,
+                                               (caddr_t)&tmpoir, oc_index_cmp );
+                                       assert( oir != NULL );
+                                       ldap_memfree( oir );
+                               }
+
+                               if ( soc->soc_oid ) {
+                                       struct oindexrec        tmpoir;
+
+                                       ber_str2bv( soc->soc_oid, 0, 0, &tmpoir.oir_name );
+                                       tmpoir.oir_oc = soc;
+                                       oir = (struct oindexrec *)avl_delete( &oc_index,
+                                               (caddr_t)&tmpoir, oc_index_cmp );
+                                       assert( oir != NULL );
+                                       ldap_memfree( oir );
+                               }
+
                                return rc;
                        }