s4:dsdb/repl: Improve memory handling in replicated schema code
authorAndrew Bartlett <abartlet@samba.org>
Thu, 4 Aug 2016 03:20:27 +0000 (15:20 +1200)
committerJeremy Allison <jra@samba.org>
Wed, 10 Aug 2016 22:49:14 +0000 (00:49 +0200)
This attempts to make it clear what memory is short term and what memory is long term

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12115

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source4/dsdb/repl/replicated_objects.c
source4/libnet/libnet_vampire.c

index fb8083d4bb4e80bfeded3a694a4902c7fbcd62d0..17b68a42d2a5cd9d2abbe74ab6f37c84bde32e0b 100644 (file)
@@ -103,7 +103,6 @@ static WERROR dsdb_repl_merge_working_schema(struct ldb_context *ldb,
 }
 
 WERROR dsdb_repl_resolve_working_schema(struct ldb_context *ldb,
-                                       TALLOC_CTX *mem_ctx,
                                        struct dsdb_schema_prefixmap *pfm_remote,
                                        uint32_t cycle_before_switching,
                                        struct dsdb_schema *initial_schema,
@@ -129,10 +128,11 @@ WERROR dsdb_repl_resolve_working_schema(struct ldb_context *ldb,
                        DRSUAPI_ATTID_systemPossSuperiors,
                        DRSUAPI_ATTID_INVALID
        };
+       TALLOC_CTX *frame = talloc_stackframe();
 
        /* create a list of objects yet to be converted */
        for (cur = first_object; cur; cur = cur->next_object) {
-               schema_list_item = talloc(mem_ctx, struct schema_list);
+               schema_list_item = talloc(frame, struct schema_list);
                if (schema_list_item == NULL) {
                        return WERR_NOMEM;
                }
@@ -164,6 +164,7 @@ WERROR dsdb_repl_resolve_working_schema(struct ldb_context *ldb,
                                                        working_schema,
                                                        resulting_schema);
                        if (!W_ERROR_IS_OK(werr)) {
+                               talloc_free(frame);
                                return werr;
                        }
                }
@@ -242,6 +243,7 @@ WERROR dsdb_repl_resolve_working_schema(struct ldb_context *ldb,
                                 "all %d remaining of %d objects "
                                 "failed to convert\n",
                                 failed_obj_count, object_count));
+                       talloc_free(frame);
                        return WERR_INTERNAL_ERROR;
                }
 
@@ -257,12 +259,14 @@ WERROR dsdb_repl_resolve_working_schema(struct ldb_context *ldb,
                        ret = dsdb_setup_sorted_accessors(ldb, working_schema);
                        if (LDB_SUCCESS != ret) {
                                DEBUG(0,("Failed to create schema-cache indexes!\n"));
+                               talloc_free(frame);
                                return WERR_INTERNAL_ERROR;
                        }
                }
                pass_no++;
        }
 
+       talloc_free(frame);
        return WERR_OK;
 }
 
@@ -298,14 +302,15 @@ WERROR dsdb_repl_make_working_schema(struct ldb_context *ldb,
 
        /* we are going to need remote prefixMap for decoding */
        werr = dsdb_schema_pfm_from_drsuapi_pfm(mapping_ctr, true,
-                                               mem_ctx, &pfm_remote, NULL);
+                                               working_schema, &pfm_remote, NULL);
        if (!W_ERROR_IS_OK(werr)) {
                DEBUG(0,(__location__ ": Failed to decode remote prefixMap: %s",
                         win_errstr(werr)));
+               talloc_free(working_schema);
                return werr;
        }
 
-       werr = dsdb_repl_resolve_working_schema(ldb, mem_ctx,
+       werr = dsdb_repl_resolve_working_schema(ldb,
                                                pfm_remote,
                                                0, /* cycle_before_switching */
                                                working_schema,
@@ -315,6 +320,7 @@ WERROR dsdb_repl_make_working_schema(struct ldb_context *ldb,
        if (!W_ERROR_IS_OK(werr)) {
                DEBUG(0, ("%s: dsdb_repl_resolve_working_schema() failed: %s",
                          __location__, win_errstr(werr)));
+               talloc_free(working_schema);
                return werr;
        }
 
index 0186caf0617e4865156b44508e6bbe8219427897..60bfa419f90b544fe68840492f518f66bc1ba80e 100644 (file)
@@ -332,7 +332,7 @@ static NTSTATUS libnet_vampire_cb_apply_schema(struct libnet_vampire_cb_state *s
                                                 "become dc",
                                                 "schema convert retrial", 1);
 
-       status = dsdb_repl_resolve_working_schema(s->ldb, s,
+       status = dsdb_repl_resolve_working_schema(s->ldb,
                                                  pfm_remote,
                                                  cycle_before_switching,
                                                  provision_schema,