From 51d2779a60b0b5d358e0b3473324ce4b606d52b7 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 4 Jul 2016 14:06:10 +1200 Subject: [PATCH] schema: Reorder dsdb_set_schema() to unlink the old schema last Signed-off-by: Andrew Bartlett Reviewed-by: Garming Sam --- source4/dsdb/schema/schema_set.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/source4/dsdb/schema/schema_set.c b/source4/dsdb/schema/schema_set.c index 6029e46a7a1..1b29c4dce4b 100644 --- a/source4/dsdb/schema/schema_set.c +++ b/source4/dsdb/schema/schema_set.c @@ -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_use_global_schema", NULL); + if (ret != LDB_SUCCESS) { + return ret; + } + ret = ldb_set_opaque(ldb, "dsdb_schema", schema); 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); - if (ret != LDB_SUCCESS) { - return ret; - } - /* 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; } /**