talloc_tos(), returning talloc_tos() memory and the talloc_stackframe order protection
jra at samba.org
Fri Jun 22 16:34:19 UTC 2018
On Fri, Jun 22, 2018 at 07:36:38AM +0200, Stefan Metzmacher via samba-technical wrote:
> Am 22.06.2018 um 07:25 schrieb Andrew Bartlett via samba-technical:
> > Why do we have functions like create_conn_struct_tos() then?
> This is a special case! The code we had before was much worse
> it created connection_struct which did sometime chdir and forgot to
> chdir back and call VFS_DISCONNECT when done.
> create_conn_struct_[cwd]_tos() is now only usable in one code block
> that starts with frame = talloc_stackframe() and ends with
> TALLOC_FREE(frame). This implements a restriction similar to
> become_root()/unbecome_root() which always be used as pair
> wrapping a specific shortterm section.
> It's intended that the caller only have a change to control the lifetime
> of the connection_struct by using this pattern and hopefully don't
> find a ways to skip the destructor from being called.
Yes. I wrote the original (horrible) create_conn_struct() code
and Metze's changes are a *significant* improvement on that.
The original idea as Metze says was to create a temporary
conn struct valid only within a call stack to allow functions
to be called from the msdfs code.
It's much clearer using a talloc_tos() context.
More information about the samba-technical