From: Andrew Bartlett Date: Thu, 4 Aug 2016 03:20:27 +0000 (+1200) Subject: s4:dsdb/repl: Improve memory handling in replicated schema code X-Git-Tag: tevent-0.9.30~161 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c533b60ceb761b609e78dfe270930cb99fdac848;p=thirdparty%2Fsamba.git s4:dsdb/repl: Improve memory handling in replicated schema code 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 Reviewed-by: Stefan Metzmacher --- diff --git a/source4/dsdb/repl/replicated_objects.c b/source4/dsdb/repl/replicated_objects.c index fb8083d4bb4..17b68a42d2a 100644 --- a/source4/dsdb/repl/replicated_objects.c +++ b/source4/dsdb/repl/replicated_objects.c @@ -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; } diff --git a/source4/libnet/libnet_vampire.c b/source4/libnet/libnet_vampire.c index 0186caf0617..60bfa419f90 100644 --- a/source4/libnet/libnet_vampire.c +++ b/source4/libnet/libnet_vampire.c @@ -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,