r2675: added a convenience function
authorAndrew Tridgell <tridge@samba.org>
Mon, 27 Sep 2004 05:13:00 +0000 (05:13 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:59:20 +0000 (12:59 -0500)
commit61a7dfc2371c65bce0bf15ef868b40921cd81756
tree51c922eb59aee4a4a2c338a6d143af0440cb9ee6
parent351ca44e8b3ea8336abba8215dfc1ccb42458384
r2675: added a convenience function

  void *talloc_reference(const void *context, const void *ptr);

this function makes a secondary reference to ptr, and hangs it off the
given context. This greatly simplifies some of the current reference
counting code in the samr server and I suspect it will be widely used
in other places too.

the way you use it is like this:

domain_state->connect_state = talloc_reference(domain_state, connect_state);

that makes the element connect_state of domain_state a secondary
reference to connect_state. The connect_state structure will then only
be freed when both domain_state and the original connect_state go
away, allowing you to free them independently and in any order.

you could do this alrady using a talloc destructor, and that is what
the samr server did previously, but that meant this construct was
being reinvented in several places. So this convenience function sets
up the destructor for you, giving a much more convenient and less
error prone API.
(This used to be commit dc5315086156644fad093cbe6b02d999adba8540)
source4/lib/talloc.c
source4/rpc_server/samr/dcesrv_samr.c