[QUICK] talloc bugs

tridge at samba.org tridge at samba.org
Mon Jun 29 05:58:54 MDT 2009

Hi Sam,

 > However depending on the meaning of your clause "disallow direct
 > talloc_free() of a pointer that has outstanding references" this
 > constraint on talloc_free could lead instead to memory leaks.

First off I'd propose that for a test patch we abort() if you
talloc_free() a pointer with a reference. Then we can run 'make test'
and see just how often this happens. I think it will be very rare, and
we may even find it doesn't happen at all outside of the talloc test

So if you did this:

  int *p1 = talloc_new(NULL);
  int *p2 = talloc_new(NULL);
  int *c1 = talloc(p1, int);
  int *r1 = talloc_reference(p1, c1);

then if you call talloc_free(c1 /* == r1 */) you will abort. 

If you call talloc_free(p1) or talloc_free(p2) then you will get the
current behaviour, as there is no ambiguity. 

If you call talloc_unlink(p1, c1) or talloc_unlink(p2, r1) then it
will free the appropriate parent/reference.

Whether we can live with this is yet to be seen. We need to try it,
see if we have come to depend on the ambiguity, and if we have then
deal with it.

My guess is we have very few bits of code that depend on this

Cheers, Tridge

More information about the samba-technical mailing list