schema: Reorder dsdb_set_schema() to unlink the old schema last
authorAndrew Bartlett <abartlet@samba.org>
Mon, 4 Jul 2016 02:06:10 +0000 (14:06 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 6 Jul 2016 13:35:17 +0000 (15:35 +0200)
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
source4/dsdb/schema/schema_set.c

index 6029e46a7a1724a9239ee01a801be90b0196f468..1b29c4dce4b3beaa800ccca3fe27008e2286dcec 100644 (file)
@@ -475,32 +475,33 @@ int dsdb_set_schema(struct ldb_context *ldb, struct dsdb_schema *schema)
 
        old_schema = ldb_get_opaque(ldb, "dsdb_schema");
 
-       ret = ldb_set_opaque(ldb, "dsdb_schema", schema);
+       ret = ldb_set_opaque(ldb, "dsdb_use_global_schema", NULL);
        if (ret != LDB_SUCCESS) {
                return ret;
        }
 
-       /* Remove the reference to the schema we just overwrote - if there was
-        * none, NULL is harmless here */
-       if (old_schema != schema) {
-               talloc_unlink(ldb, old_schema);
-               talloc_steal(ldb, schema);
-       }
-
-       talloc_steal(ldb, schema);
-
-       ret = ldb_set_opaque(ldb, "dsdb_use_global_schema", NULL);
+       ret = ldb_set_opaque(ldb, "dsdb_schema", schema);
        if (ret != LDB_SUCCESS) {
                return ret;
        }
 
+       talloc_steal(ldb, schema);
+
        /* Set the new attributes based on the new schema */
        ret = dsdb_schema_set_indices_and_attributes(ldb, schema, true);
        if (ret != LDB_SUCCESS) {
                return ret;
        }
 
-       return LDB_SUCCESS;
+       /*
+        * Remove the reference to the schema we just overwrote - if there was
+        * none, NULL is harmless here.
+        */
+       if (old_schema != schema) {
+               talloc_unlink(ldb, old_schema);
+       }
+
+       return ret;
 }
 
 /**