[PATCH] Use talloc_autofree_context() to allocate global memory

Andrew Bartlett abartlet at samba.org
Mon Sep 8 19:03:19 MDT 2014


On Mon, 2014-09-08 at 14:22 +0200, Kamen Mazdrashki wrote:
> Hi,
> 
> 
> Please find attached several patches to move global structure off of
> NULL
> context into autofree context.
> I have hit those while running unit tests in Openchange.
> 
> 
> Strictly speaking, patch 0002 is not needed as the caller for this
> function
> uses the memory returned and frees it immediately - we have only 1
> caller
> at the moment.
> Nevertheless, we can't assume what the caller of
> debug_list_class_names_and_levels()
> is going to do and hence this patch. May be it will be good if we pass
> memory context explicitly?
> 
> 
> Please review.

Thanks Kamen,

I'm trying to remember why we went a bit cold on
talloc_autofree_context().  I know we got into trouble when it involved
destructors. 

That said, changes like the one in 

[PATCH 5/5] loadparm: Allocate bitmap structures in autofree context

are probably wrong.  We should use the pservice as a talloc parent,
unless there is a good reason.

I also think that if you have to write an explanation like the one in:
[PATCH 2/5] util/debug: debug_list_class_names_and_levels - alloc mem
 off of autofree context

that this means the patch is wrong - talloc_autofree_context() should be
the very last resort, not the first, because it hides exactly the bugs
you are worried about. 

> A quick summary of changes:
>  lib/ldb/common/ldb_modules.c |  6 +++---
>  lib/param/loadparm.c         |  2 +-
>  lib/tevent/tevent.c          |  2 +-
>  lib/util/debug.c             | 12 +++++++++---
>  4 files changed, 14 insertions(+), 8 deletions(-)
> 
> 
> patches also pushed at:
> https://github.com/kamenim/samba/commits/util-debug-use-autofree-context
> 
> (probing what will be the feedback for Github :) 
> 
> 
> Cheers,
> kamen

-- 
Andrew Bartlett
http://samba.org/~abartlet/
Authentication Developer, Samba Team  http://samba.org
Samba Developer, Catalyst IT          http://catalyst.net.nz/services/samba






More information about the samba-technical mailing list