diff options
author | Volker Lendecke <vlendec@samba.org> | 2007-08-30 19:48:31 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:30:24 -0500 |
commit | 929e1d99209e20a9c2c95c8bdfc8eaa37b2c2291 (patch) | |
tree | 169c06d247826eac8c3d3054ce8de78fce7d454d /source3/rpc_server | |
parent | a646210b2b8ead5690b3c6baf058c2de6e0c1a26 (diff) | |
download | samba-929e1d99209e20a9c2c95c8bdfc8eaa37b2c2291.tar.gz samba-929e1d99209e20a9c2c95c8bdfc8eaa37b2c2291.tar.bz2 samba-929e1d99209e20a9c2c95c8bdfc8eaa37b2c2291.zip |
r24809: Consolidate the use of temporary talloc contexts.
This adds the two functions talloc_stackframe() and talloc_tos().
* When a new talloc stackframe is allocated with talloc_stackframe(), then
* the TALLOC_CTX returned with talloc_tos() is reset to that new
* frame. Whenever that stack frame is TALLOC_FREE()'ed, then the reverse
* happens: The previous talloc_tos() is restored.
*
* This API is designed to be robust in the sense that if someone forgets to
* TALLOC_FREE() a stackframe, then the next outer one correctly cleans up and
* resets the talloc_tos().
The original motivation for this patch was to get rid of the
sid_string_static & friends buffers. Explicitly passing talloc context
everywhere clutters code too much for my taste, so an implicit
talloc_tos() is introduced here. Many of these static buffers are
replaced by a single static pointer.
The intended use would thus be that low-level functions can rather
freely push stuff to talloc_tos, the upper layers clean up by freeing
the stackframe. The more of these stackframes are used and correctly
freed the more exact the memory cleanup happens.
This patch removes the main_loop_talloc_ctx, tmp_talloc_ctx and
lp_talloc_ctx (did I forget any?)
So, never do a
tmp_ctx = talloc_init("foo");
anymore, instead, use
tmp_ctx = talloc_stackframe()
:-)
Volker
(This used to be commit 6585ea2cb7f417e14540495b9c7380fe9c8c717b)
Diffstat (limited to 'source3/rpc_server')
-rw-r--r-- | source3/rpc_server/srv_pipe.c | 4 | ||||
-rw-r--r-- | source3/rpc_server/srv_spoolss_nt.c | 6 | ||||
-rw-r--r-- | source3/rpc_server/srv_srvsvc_nt.c | 5 |
3 files changed, 7 insertions, 8 deletions
diff --git a/source3/rpc_server/srv_pipe.c b/source3/rpc_server/srv_pipe.c index 7493aaddb9..fefdb529b2 100644 --- a/source3/rpc_server/srv_pipe.c +++ b/source3/rpc_server/srv_pipe.c @@ -2240,9 +2240,9 @@ BOOL api_pipe_request(pipes_struct *p) pipe_fns = find_pipe_fns_by_context(p->contexts, p->hdr_req.context_id); if ( pipe_fns ) { - set_current_rpc_talloc(p->mem_ctx); + TALLOC_CTX *frame = talloc_stackframe(); ret = api_rpcTNP(p, p->name, pipe_fns->cmds, pipe_fns->n_cmds); - set_current_rpc_talloc(NULL); + TALLOC_FREE(frame); } else { DEBUG(0,("api_pipe_request: No rpc function table associated with context [%d] on pipe [%s]\n", diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b50e1e7558..600eb2f688 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -389,7 +389,7 @@ static BOOL get_printer_snum(pipes_struct *p, POLICY_HND *hnd, int *number, DEBUG(4,("short name:%s\n", Printer->sharename)); *number = print_queue_snum(Printer->sharename); if ((*number != -1) && (params != NULL)) { - *params = get_share_params(tmp_talloc_ctx(), + *params = get_share_params(talloc_tos(), Printer->sharename); if (*params == NULL) { return False; @@ -4257,7 +4257,7 @@ static BOOL construct_printer_info_2(Printer_entry *print_hnd, /* don't use talloc_steal() here unless you do a deep steal of all the SEC_DESC members */ - printer->secdesc = dup_sec_desc( get_talloc_ctx(), + printer->secdesc = dup_sec_desc( talloc_tos(), ntprinter->info_2->secdesc_buf->sd ); } @@ -4297,7 +4297,7 @@ static BOOL construct_printer_info_3(Printer_entry *print_hnd, /* don't use talloc_steal() here unless you do a deep steal of all the SEC_DESC members */ - printer->secdesc = dup_sec_desc( get_talloc_ctx(), + printer->secdesc = dup_sec_desc( talloc_tos(), ntprinter->info_2->secdesc_buf->sd ); } diff --git a/source3/rpc_server/srv_srvsvc_nt.c b/source3/rpc_server/srv_srvsvc_nt.c index ed32f6a765..22eaac51a7 100644 --- a/source3/rpc_server/srv_srvsvc_nt.c +++ b/source3/rpc_server/srv_srvsvc_nt.c @@ -1049,7 +1049,6 @@ static WERROR init_srv_conn_info_ctr(pipes_struct *p, union srvsvc_NetConnCtr *c static WERROR net_file_enum_3(pipes_struct *p, union srvsvc_NetFileCtr *ctr, uint32 *resume_hnd, uint32 *num_entries ) { - TALLOC_CTX *ctx = get_talloc_ctx(); WERROR status; /* TODO -- Windows enumerates @@ -1058,11 +1057,11 @@ static WERROR net_file_enum_3(pipes_struct *p, union srvsvc_NetFileCtr *ctr, uin ctr->ctr3 = TALLOC_ZERO_P(p->mem_ctx, struct srvsvc_NetFileCtr3); - status = net_enum_files( ctx, &ctr->ctr3->array, num_entries, resume_hnd ); + status = net_enum_files(p->mem_ctx, &ctr->ctr3->array, num_entries, resume_hnd ); if ( !W_ERROR_IS_OK(status)) return status; - status = net_enum_pipes( ctx, &ctr->ctr3->array, num_entries, resume_hnd ); + status = net_enum_pipes(p->mem_ctx, &ctr->ctr3->array, num_entries, resume_hnd ); if ( !W_ERROR_IS_OK(status)) return status; |