CVS update: samba/source/utils

Tim Potter tpot at samba.org
Thu Nov 29 18:03:28 EST 2001


On Wed, Nov 28, 2001 at 10:21:56PM -0800, abartlet at samba.org wrote:

> Modified Files:
> 	net_ads.c net_join.c 
> Log Message:
> Make better use of the ads_init() function to get the kerberos relam etc.
> 
> This allows us to use automagically obtained values in future, and the value
> from krb5.conf now.
> 
> Also fix mem leaks etc.

One pattern I like to use that makes this sort of function neater and
less subject to new memory leaks is this:

int foo(void)
{
	ADS_STRUCT *ads = NULL;
	int retval = -1;

	/* Do stuff */

	if (failed_condition) {
		DEBUG(10, ("Jeremy likes debug statements\n"));
		goto done;
	}

	ads = ads_init("bar");

	if (another_failed_condition) {
		DEBUG(10, ("Philly Whitpot\n"));
		goto done;
	}

	/* Everything has worked */

	retval = 0;

done:
	if (!ads)
		ads_destroy(&ads);

	return retval;
}

So someone adding more code or checks in the middle doesn't have to
remember to set the return value or to do whatever cleanups are
required.  It gets more complicated if at each stage you are
allocating another structure and have to free it at every exit
path below.


Tim.




More information about the samba-cvs mailing list