]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/oc.c
syncinfo_free must be able to free multiple syncinfos
[openldap] / servers / slapd / oc.c
index bbf7be86a357305f5bb315f2218a9870de36fc1e..ef52fc869585909492cb384eda46dde365cf6814 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2006 The OpenLDAP Foundation.
+ * Copyright 1998-2007 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -135,6 +135,8 @@ static Avlnode      *oc_cache = NULL;
 static LDAP_STAILQ_HEAD(OCList, slap_object_class) oc_list
        = LDAP_STAILQ_HEAD_INITIALIZER(oc_list);
 
+ObjectClass *oc_sys_tail;
+
 static int
 oc_index_cmp(
        const void *v_oir1,
@@ -407,7 +409,7 @@ oc_delete_names( ObjectClass *oc )
 /* Mark the ObjectClass as deleted, remove from list, and remove all its
  * names from the AVL tree. Leave the OID in the tree.
  */
-int
+void
 oc_delete( ObjectClass *oc )
 {
        oc->soc_flags |= SLAP_OC_DELETED;
@@ -415,17 +417,27 @@ oc_delete( ObjectClass *oc )
        LDAP_STAILQ_REMOVE(&oc_list,oc,slap_object_class,soc_next);
 
        oc_delete_names( oc );
-
-       return 0;
 }
 
 static void
 oc_clean( ObjectClass *o )
 {
-       if (o->soc_sups) ldap_memfree(o->soc_sups);
-       if (o->soc_required) ldap_memfree(o->soc_required);
-       if (o->soc_allowed) ldap_memfree(o->soc_allowed);
-       if (o->soc_oidmacro) ldap_memfree(o->soc_oidmacro);
+       if (o->soc_sups) {
+               ldap_memfree(o->soc_sups);
+               o->soc_sups = NULL;
+       }
+       if (o->soc_required) {
+               ldap_memfree(o->soc_required);
+               o->soc_required = NULL;
+       }
+       if (o->soc_allowed) {
+               ldap_memfree(o->soc_allowed);
+               o->soc_allowed = NULL;
+       }
+       if (o->soc_oidmacro) {
+               ldap_memfree(o->soc_oidmacro);
+               o->soc_oidmacro = NULL;
+       }
 }
 
 static void
@@ -476,7 +488,7 @@ oc_next( ObjectClass **oc )
 {
        assert( oc != NULL );
 
-#if 1  /* pedantic check */
+#if 0  /* pedantic check: breaks when deleting an oc, don't use it. */
        {
                ObjectClass *tmp = NULL;
 
@@ -671,7 +683,15 @@ oc_insert(
                        names++;
                }
        }
-       LDAP_STAILQ_INSERT_TAIL( &oc_list, soc, soc_next );
+       if ( soc->soc_flags & SLAP_OC_HARDCODE ) {
+               prev = oc_sys_tail;
+               oc_sys_tail = soc;
+       }
+       if ( prev ) {
+               LDAP_STAILQ_INSERT_AFTER( &oc_list, prev, soc, soc_next );
+       } else {
+               LDAP_STAILQ_INSERT_TAIL( &oc_list, soc, soc_next );
+       }
 
        return 0;
 }
@@ -798,7 +818,7 @@ oc_unparse( BerVarray *res, ObjectClass *start, ObjectClass *end, int sys )
        /* count the result size */
        i = 0;
        for ( oc=start; oc; oc=LDAP_STAILQ_NEXT(oc, soc_next)) {
-               if ( sys && !(oc->soc_flags & SLAP_OC_HARDCODE)) continue;
+               if ( sys && !(oc->soc_flags & SLAP_OC_HARDCODE)) break;
                i++;
                if ( oc == end ) break;
        }
@@ -815,7 +835,7 @@ oc_unparse( BerVarray *res, ObjectClass *start, ObjectClass *end, int sys )
        i = 0;
        for ( oc=start; oc; oc=LDAP_STAILQ_NEXT(oc, soc_next)) {
                LDAPObjectClass loc, *locp;
-               if ( sys && !(oc->soc_flags & SLAP_OC_HARDCODE)) continue;
+               if ( sys && !(oc->soc_flags & SLAP_OC_HARDCODE)) break;
                if ( oc->soc_oidmacro ) {
                        loc = oc->soc_oclass;
                        loc.oc_oid = oc->soc_oidmacro;