s4:s3compat Avoid talloc_free() with references
authorAndrew Bartlett <abartlet@samba.org>
Mon, 17 May 2010 09:08:19 +0000 (19:08 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 3 Jun 2010 01:14:10 +0000 (11:14 +1000)
The ldb context is referenced, so free via a parent.

Andrew Bartlett

source4/s3compat/machine_sid.c

index 947530cf897c5fbba88d06375cf25447346a78cc..8291b759e9a88afbd290ad69585f432bc65c8ab7 100644 (file)
@@ -33,23 +33,31 @@ struct dom_sid *get_global_sam_sid(void)
 {
        const struct dom_sid *tmp_dom_sid;
        struct ldb_context *samdb;
+       TALLOC_CTX *tmp_ctx;
        if (global_sam_sid) {
                return global_sam_sid;
        }
-       samdb = samdb_connect(NULL, s3compat_get_tevent_ctx(), 
+       tmp_ctx = talloc_new(NULL);
+       if (!tmp_ctx) {
+               return NULL;
+       }
+                      
+       samdb = samdb_connect(tmp_ctx, s3compat_get_tevent_ctx(), 
                              s3compat_get_lp_ctx(), 
                              system_session(s3compat_get_lp_ctx()));
        if (!samdb) {
                DEBUG(0, ("Failed to open samdb to return global_sam_sid\n"));
+               talloc_free(tmp_ctx);
                return NULL;
        }
        tmp_dom_sid = samdb_domain_sid(samdb);
        if (!tmp_dom_sid) {
                DEBUG(0, ("Failed to obtain domain sid from samdb to return global_sam_sid\n"));
+               talloc_free(tmp_ctx);
                return NULL;
        }
        global_sam_sid = dom_sid_dup(talloc_autofree_context(), tmp_dom_sid);
-       talloc_free(samdb);
+       talloc_free(tmp_ctx);
        if (!global_sam_sid) {
                DEBUG(0, ("Failed to duplicate domain sid to return global_sam_sid\n"));
                return NULL;