talloc_tos in shadow_copy2_insert_string

Richard Sharpe realrichardsharpe at gmail.com
Tue Mar 27 12:07:34 MDT 2012


On 3/27/12, Volker Lendecke <Volker.Lendecke at sernet.de> wrote:
> On Tue, Mar 27, 2012 at 08:16:30AM -0700, Richard Sharpe wrote:
>> My understanding was that things allocated with a talloc_tos() context
>> are cleaned up when the current SMB request is finished with.
>>
>> However, it would be useful to find out exactly what the meaning of
>> talloc_tos() is.
>
> From talloc_stackframe.h:
>
> /*
>
>  * Implement a stack of talloc frames.
>
>  *
>
>  * 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 intended use is that talloc_tos() is used for anything
> within a function. Returning something on talloc_tos() is
> not the best style, because it means that this object will
> go away once the surrounding talloc_stackframe() goes. It
> will work okay if used in a controlled manner, but depending
> on local circumstances alternatives might be more
> understandable.

Shame on me. I should have read the code :-(

-- 
Regards,
Richard Sharpe
(何以解憂?唯有杜康。--曹操)


More information about the samba-technical mailing list