talloc_stack.c?

tridge at samba.org tridge at samba.org
Mon Jul 2 05:22:38 GMT 2007


Volker,

 > +/*
 > + * Implement a stack of talloc frames. We can't rely on a linked list with
 > + * talloc destructors because in a hierarchy of talloc destructors the parent
 > + * destructor is called before its children destructors.
 > + */

linked lists work fine - I use them all the time with talloc
destructors. 

You are right that the parent destructor is called first, but the
memory is actually freed from the bottom up (ie. child is freed
first). The recursion marks the memory for deletion on the way down
(to prevent loops) and actually frees it on the way up.

Did you try and use talloc destructors with linked lists and hit a
problem or did you just assume they wouldn't work from looking at the
code? If they didn't work, can you post a snippet of code showing what
you tried to do?

Regarding the talloc_stack.c idea, this is awfully similar to what we
have had in the past with a "loop" memory context - a memory context
that gets freed in the top level event loop. What advantage does
talloc_stack have over that idea? (that idea is still present in the
lp_TALLOC_FREE() call and tmp_talloc_ctx() in Samba3.

(what is this obsession with capitalising routine names? I sometimes
wonder if some people think that CAPITALS makes code less buggy?)

Cheers, Tridge


More information about the samba-technical mailing list