[QUICK] talloc bugs
idra at samba.org
Mon Jun 29 07:16:48 MDT 2009
On Mon, 2009-06-29 at 22:58 +1000, ronnie sahlberg wrote:
> The reason that a linked list in talloc today requires that you do
> walk the list when you need to fix up the dangling reference is
> because of talloc being a tree structure and certain data models like
> linked lists are not tree structured but graphs.
Sorry Ronnie, but I totally disagree here.
The reason you have to walk a list is that you really needed a double
linked list and instead went for a single linked list.
What you are doing with talloc_reference() here is really just creating
a double linked list, only you do one part explicitly (the ->next part)
and tie the second to memory allocation ( -> parent part).
I think this is a *very* good example of a *very* bad way to use memory
hierarchies or references.
Not only you have nothing more than a double linked list, but you have
to deal with the 2 pointers (next/prev) in 2 completely different ways.
Not to think about the weirdness of using 2 different ways to deal with
list removal depending on whether you want to free the object or simply
remove it from the list and use it elsewhere.
A double linked list element should simply use a destructor and
The only case where this usage could be of use is if the actual object
structure is imposed on you. But in most cases where that happens you
have to deal with other code that uses normal malloc/free most probably.
Samba Team GPL Compliance Officer <simo at samba.org>
Principal Software Engineer at Red Hat, Inc. <simo at redhat.com>
More information about the samba-technical