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/param | |
parent | a646210b2b8ead5690b3c6baf058c2de6e0c1a26 (diff) | |
download | samba-929e1d99209e20a9c2c95c8bdfc8eaa37b2c2291.tar.gz samba-929e1d99209e20a9c2c95c8bdfc8eaa37b2c2291.tar.xz 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/param')
-rw-r--r-- | source3/param/loadparm.c | 44 |
1 files changed, 5 insertions, 39 deletions
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index 7e573052e18..3dd94645fd0 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -1708,33 +1708,6 @@ static void init_globals(BOOL first_time_only) Globals.bRegistryShares = False; } -static TALLOC_CTX *lp_talloc; - -/******************************************************************* a - Free up temporary memory - called from the main loop. -********************************************************************/ - -void lp_TALLOC_FREE(void) -{ - if (!lp_talloc) - return; - TALLOC_FREE(lp_talloc); - lp_talloc = NULL; -} - -TALLOC_CTX *tmp_talloc_ctx(void) -{ - if (lp_talloc == NULL) { - lp_talloc = talloc_init("tmp_talloc_ctx"); - } - - if (lp_talloc == NULL) { - smb_panic("Could not create temporary talloc context"); - } - - return lp_talloc; -} - /******************************************************************* Convenience routine to grab string parameters into temporary memory and run standard_sub_basic on them. The buffers can be written to by @@ -1754,9 +1727,6 @@ static char *lp_string(const char *s) DEBUG(10, ("lp_string(%s)\n", s)); #endif - if (!lp_talloc) - lp_talloc = talloc_init("lp_talloc"); - tmpstr = alloc_sub_basic(get_current_username(), current_user_info.domain, s); if (trim_char(tmpstr, '\"', '\"')) { @@ -1766,7 +1736,7 @@ static char *lp_string(const char *s) current_user_info.domain, s); } } - ret = talloc_strdup(lp_talloc, tmpstr); + ret = talloc_strdup(talloc_tos(), tmpstr); SAFE_FREE(tmpstr); return (ret); @@ -2352,7 +2322,7 @@ static int lp_enum(const char *s,const struct enum_list *_enum) /* Return parametric option from a given service. Type is a part of option before ':' */ /* Parametric option has following syntax: 'Type: option = value' */ -/* the returned value is talloced in lp_talloc */ +/* the returned value is talloced on the talloc_tos() */ char *lp_parm_talloc_string(int snum, const char *type, const char *option, const char *def) { param_opt_struct *data = get_parametrics(snum, type, option); @@ -3917,10 +3887,8 @@ static const char *append_ldap_suffix( const char *str ) const char *suffix_string; - if (!lp_talloc) - lp_talloc = talloc_init("lp_talloc"); - - suffix_string = talloc_asprintf( lp_talloc, "%s,%s", str, Globals.szLdapSuffix ); + suffix_string = talloc_asprintf(talloc_tos(), "%s,%s", str, + Globals.szLdapSuffix ); if ( !suffix_string ) { DEBUG(0,("append_ldap_suffix: talloc_asprintf() failed!\n")); return ""; @@ -5567,8 +5535,6 @@ void gfree_loadparm(void) struct file_lists *next; int i; - lp_TALLOC_FREE(); - /* Free the file lists */ f = file_lists; @@ -5912,7 +5878,7 @@ const char *volume_label(int snum) } /* This returns a 33 byte guarenteed null terminated string. */ - ret = talloc_strndup(main_loop_talloc_get(), label, 32); + ret = talloc_strndup(talloc_tos(), label, 32); if (!ret) { return ""; } |