[PATCH] Allow mixing of talloc_reference and talloc_free

Sam Liddicott sam at liddicott.com
Wed Dec 17 16:53:18 GMT 2008


Here is fuller patch that makes libtalloc more sane.
[Samba crashes all over the place with it though]

One insanity is that talloc_free will remove the most recent reference
instead of freeing (if there is any references), and leaves the original
owner. This can lead to memory leaks; but if the original owner is also
later free'd then the reference (which has since been removed) can't do
it's job either, and can't keep the memory valid.

This change permits talloc_free only to be called once per allocation
(unless a steal has been done), and is equivalent to talloc_unlink but
passing the original owner to be unlinked, and leaving any references
intact to do their job.

An effect is that you can no longer do:

ref=talloc_reference(ctx, thing);
..
talloc_free(ref);

but that was misleading anyway and didn't work as expected if there were
intervening talloc_reference or talloc_free

The test suite is also patched to cover the change.

[PATCH] Allow mixing of talloc_reference and talloc_free

Store the allocating mem_ctx (or stealing mem_ctx) so that
talloc_free can really do talloc_unlink; thus permitting
talloc_free to be safely called on memory that may be
referenced elsewhere.


NOT Signed-off
---
 lib/talloc/talloc.c    |   64
+++++++++++++++++++++++++++++++++++++----------
 lib/talloc/testsuite.c |   37 +++++++++++++++++----------
 2 files changed, 73 insertions(+), 28 deletions(-)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: 91b5451132513c8dea2c69afa34f3acf03fd9322.diff
Type: text/x-patch
Size: 9872 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20081217/4dfcb63e/91b5451132513c8dea2c69afa34f3acf03fd9322.bin


More information about the samba-technical mailing list