s4:objectclass LDB module - move "mem_ctx" initialisation lower
authorMatthias Dieter Wallnöfer <mdw@samba.org>
Thu, 17 Jun 2010 13:27:50 +0000 (15:27 +0200)
committerMatthias Dieter Wallnöfer <mdw@samba.org>
Fri, 18 Jun 2010 08:03:09 +0000 (10:03 +0200)
Saves us some "talloc_free"s on error cases

source4/dsdb/samdb/ldb_modules/objectclass.c

index 2df809701c64df1db3315cb23f0ca198bb2c4f94..e5769a63ddfae3862e59c0487d4f63947d9034ad 100644 (file)
@@ -414,57 +414,52 @@ static int objectclass_do_add(struct oc_context *ac)
 {
        struct ldb_context *ldb;
        struct ldb_request *add_req;
-       char *value;
        struct ldb_message_element *objectclass_element, *el;
        struct ldb_message *msg;
        TALLOC_CTX *mem_ctx;
        struct class_list *sorted, *current;
-       int ret;
+       const char *rdn_name = NULL;
+       char *value;
        const struct dsdb_class *objectclass;
        int32_t systemFlags = 0;
-       const char *rdn_name = NULL;
+       int ret;
 
        ldb = ldb_module_get_ctx(ac->module);
 
-       mem_ctx = talloc_new(ac);
-       if (mem_ctx == NULL) {
-               ldb_oom(ldb);
-               return LDB_ERR_OPERATIONS_ERROR;
-       }
-
        msg = ldb_msg_copy_shallow(ac, ac->req->op.add.message);
 
        /* Check if we have a valid parent - this check is needed since
         * we don't get a LDB_ERR_NO_SUCH_OBJECT error. */
        if (ac->search_res == NULL) {
                if (ldb_dn_compare(ldb_get_root_basedn(ldb), msg->dn) == 0) {
-                       /* Allow the tree to be started */
-                       
-                       /* but don't keep any error string, it's meaningless */
+                       /* Allow the tree to be started but don't keep any
+                        * error strings - they're meaningless. */
                        ldb_set_errstring(ldb, NULL);
                } else {
                        ldb_asprintf_errstring(ldb, "objectclass: Cannot add %s, parent does not exist!", 
                                               ldb_dn_get_linearized(msg->dn));
-                       talloc_free(mem_ctx);
                        return LDB_ERR_NO_SUCH_OBJECT;
                }
        } else {
-
                /* Fix up the DN to be in the standard form, taking
                 * particular care to match the parent DN */
                ret = fix_dn(msg, 
                             ac->req->op.add.message->dn,
                             ac->search_res->message->dn,
                             &msg->dn);
-
                if (ret != LDB_SUCCESS) {
                        ldb_asprintf_errstring(ldb, "objectclass: Could not munge DN %s into normal form",
                                               ldb_dn_get_linearized(ac->req->op.add.message->dn));
-                       talloc_free(mem_ctx);
                        return ret;
                }
+       }
 
+       mem_ctx = talloc_new(ac);
+       if (mem_ctx == NULL) {
+               ldb_oom(ldb);
+               return LDB_ERR_OPERATIONS_ERROR;
        }
+
        if (ac->schema != NULL) {
                /* This is now the objectClass list from the database */
                objectclass_element = ldb_msg_find_element(msg, "objectClass");