[RFC] idmap_nss plugin architecture for winbindd

simo idra at samba.org
Thu Nov 16 15:09:02 GMT 2006


On Thu, 2006-11-16 at 06:59 -0800, Gerald (Jerry) Carter wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> simo wrote:
> 
> > Very simple and clean.
> > Looks good to me.
> > 
> > I think it would be good to use the same way to define domains and
> > options I used for the new idmap backend.
> > 
> > Also is there a reason why you don't use talloc in new code ?
> 
> In what code specifically ?  The nss_domain_entry list
> is talloced.  I tend to use talloc where it makes sense to
> maintain a context, but malloc for simple short lived
> singular items.

I tend to always use talloc, eventually by creating a local context, I
found this way you the code is more readable and you can avoid memory
leaking more easily.

This is the template function I use usually in pseudo code:

void function(void *mem_ctx)
{
	local_ctx = talloc(mem_ctx);

	local1 = talloc(local_ctx);
	IF (!local1) goto done;

	...
	nonlocal = talloc(mem_ctx);
	if (!nonlocal) goto done;

	...
	if (err) goto done;

	local2 = talloc(local_ctx);
	if (!local2) goto done;

	...
	if (err) goto done;
	...
	...


done:
	talloc_free(local_ctx);
	return;

}


This way you don't have to take care of all single allocations locally
you have just to think what have to be local and what have to me long
term (if anything) so that when you exit (always through the "done"
label) you are sure all local memory is freed.
It makes also code more readable as you don't need a lot of free() calls
everywhere before returning.

Simo.

-- 
Simo Sorce
Samba Team GPL Compliance Officer
email: idra at samba.org
http://samba.org



More information about the samba-technical mailing list