s4:objectclass LDB module - move the "mem_ctx" allocation to a better place
authorMatthias Dieter Wallnöfer <mdw@samba.org>
Fri, 26 Nov 2010 12:03:59 +0000 (13:03 +0100)
committerMatthias Dieter Wallnöfer <mdw@samba.org>
Fri, 26 Nov 2010 12:10:00 +0000 (13:10 +0100)
It's only needed if we've a schema around.

source4/dsdb/samdb/ldb_modules/objectclass.c

index 66e6e393eabada7c3b579e62d359c3fb241d363d..edc9fabd5c80f13628bc20cd1b57ca76ddc00503 100644 (file)
@@ -514,26 +514,24 @@ static int objectclass_do_add(struct oc_context *ac)
                }
        }
 
-       mem_ctx = talloc_new(ac);
-       if (mem_ctx == NULL) {
-               return ldb_module_oom(ac->module);
-       }
-
        if (ac->schema != NULL) {
                objectclass_element = ldb_msg_find_element(msg, "objectClass");
                if (!objectclass_element) {
                        ldb_asprintf_errstring(ldb, "objectclass: Cannot add %s, no objectclass specified!",
                                               ldb_dn_get_linearized(msg->dn));
-                       talloc_free(mem_ctx);
                        return LDB_ERR_OBJECT_CLASS_VIOLATION;
                }
                if (objectclass_element->num_values == 0) {
                        ldb_asprintf_errstring(ldb, "objectclass: Cannot add %s, at least one (structural) objectclass has to be specified!",
                                               ldb_dn_get_linearized(msg->dn));
-                       talloc_free(mem_ctx);
                        return LDB_ERR_CONSTRAINT_VIOLATION;
                }
 
+               mem_ctx = talloc_new(ac);
+               if (mem_ctx == NULL) {
+                       return ldb_module_oom(ac->module);
+               }
+
                /* Here we do now get the "objectClass" list from the
                 * database. */
                ret = objectclass_sort(ac->module, ac->schema, mem_ctx,
@@ -594,6 +592,7 @@ static int objectclass_do_add(struct oc_context *ac)
                                                       "objectclass: object class '%s' is LSA-specific, rejecting creation of '%s' over LDAP!",
                                                       objectclass_name,
                                                       ldb_dn_get_linearized(msg->dn));
+                               talloc_free(mem_ctx);
                                return LDB_ERR_UNWILLING_TO_PERFORM;
                        }