summaryrefslogtreecommitdiff
path: root/source4/dsdb/schema
diff options
context:
space:
mode:
authorKamen Mazdrashki <kamenim@samba.org>2010-06-19 12:30:36 +0300
committerKamen Mazdrashki <kamenim@samba.org>2010-06-21 02:57:56 +0300
commitcc7e2c10f2b944fd7eac4ff11e9d48fac0043030 (patch)
tree9ef09f2c705c39f4a4d464a5b4c52004063f70ca /source4/dsdb/schema
parent267645ca55f7825e87a098c9dc51f132aac1f452 (diff)
downloadsamba-cc7e2c10f2b944fd7eac4ff11e9d48fac0043030.tar.gz
samba-cc7e2c10f2b944fd7eac4ff11e9d48fac0043030.tar.bz2
samba-cc7e2c10f2b944fd7eac4ff11e9d48fac0043030.zip
s4/dsdb: Move schema accessors cleanup in separate function
This way dsdb_setup_sorted_accessors() will free memory allocated for accessor arrays correctly in case of failure,
Diffstat (limited to 'source4/dsdb/schema')
-rw-r--r--source4/dsdb/schema/schema_set.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/source4/dsdb/schema/schema_set.c b/source4/dsdb/schema/schema_set.c
index fc255a1cd3..c9d6356804 100644
--- a/source4/dsdb/schema/schema_set.c
+++ b/source4/dsdb/schema/schema_set.c
@@ -221,6 +221,24 @@ static int dsdb_compare_attribute_by_linkID(struct dsdb_attribute **a1, struct d
return uint32_cmp((*a1)->linkID, (*a2)->linkID);
}
+/**
+ * Clean up Classes and Attributes accessor arrays
+ */
+static void dsdb_sorted_accessors_free(struct dsdb_schema *schema)
+{
+ /* free classes accessors */
+ TALLOC_FREE(schema->classes_by_lDAPDisplayName);
+ TALLOC_FREE(schema->classes_by_governsID_id);
+ TALLOC_FREE(schema->classes_by_governsID_oid);
+ TALLOC_FREE(schema->classes_by_cn);
+ /* free attribute accessors */
+ TALLOC_FREE(schema->attributes_by_lDAPDisplayName);
+ TALLOC_FREE(schema->attributes_by_attributeID_id);
+ TALLOC_FREE(schema->attributes_by_msDS_IntId);
+ TALLOC_FREE(schema->attributes_by_attributeID_oid);
+ TALLOC_FREE(schema->attributes_by_linkID);
+}
+
/*
create the sorted accessor arrays for the schema
*/
@@ -232,10 +250,8 @@ static int dsdb_setup_sorted_accessors(struct ldb_context *ldb,
unsigned int i;
unsigned int num_int_id;
- talloc_free(schema->classes_by_lDAPDisplayName);
- talloc_free(schema->classes_by_governsID_id);
- talloc_free(schema->classes_by_governsID_oid);
- talloc_free(schema->classes_by_cn);
+ /* free all caches */
+ dsdb_sorted_accessors_free(schema);
/* count the classes */
for (i=0, cur=schema->classes; cur; i++, cur=cur->next) /* noop */ ;
@@ -267,11 +283,6 @@ static int dsdb_setup_sorted_accessors(struct ldb_context *ldb,
TYPESAFE_QSORT(schema->classes_by_cn, schema->num_classes, dsdb_compare_class_by_cn);
/* now build the attribute accessor arrays */
- talloc_free(schema->attributes_by_lDAPDisplayName);
- talloc_free(schema->attributes_by_attributeID_id);
- talloc_free(schema->attributes_by_msDS_IntId);
- talloc_free(schema->attributes_by_attributeID_oid);
- talloc_free(schema->attributes_by_linkID);
/* count the attributes
* and attributes with msDS-IntId set */
@@ -323,15 +334,7 @@ static int dsdb_setup_sorted_accessors(struct ldb_context *ldb,
return LDB_SUCCESS;
failed:
- schema->classes_by_lDAPDisplayName = NULL;
- schema->classes_by_governsID_id = NULL;
- schema->classes_by_governsID_oid = NULL;
- schema->classes_by_cn = NULL;
- schema->attributes_by_lDAPDisplayName = NULL;
- schema->attributes_by_attributeID_id = NULL;
- schema->attributes_by_msDS_IntId = NULL;
- schema->attributes_by_attributeID_oid = NULL;
- schema->attributes_by_linkID = NULL;
+ dsdb_sorted_accessors_free(schema);
ldb_oom(ldb);
return LDB_ERR_OPERATIONS_ERROR;
}