? build-me ? pchdir ? update-samba ? intl/libgettext.h Index: include/ads.h =================================================================== RCS file: /data/cvs/samba/source/include/ads.h,v retrieving revision 1.12.2.13 diff -u -r1.12.2.13 ads.h --- include/ads.h 9 Jan 2004 14:54:33 -0000 1.12.2.13 +++ include/ads.h 22 Mar 2004 21:32:56 -0000 @@ -10,6 +10,8 @@ time_t last_attempt; /* last attempt to reconnect */ int ldap_port; + int is_mine; /* do I own this structure's memory? */ + /* info needed to find the server */ struct { char *realm; Index: libads/ads_struct.c =================================================================== RCS file: /data/cvs/samba/source/libads/ads_struct.c,v retrieving revision 1.13.2.7 diff -u -r1.13.2.7 ads_struct.c --- libads/ads_struct.c 22 Oct 2003 23:38:19 -0000 1.13.2.7 +++ libads/ads_struct.c 22 Mar 2004 21:32:59 -0000 @@ -102,13 +102,10 @@ ads->server.foreign = 1; } - return ads; -} + /* the caller will own the memory by default */ + ads->is_mine = 1; -/* a simpler ads_init() interface using all defaults */ -ADS_STRUCT *ads_init_simple(void) -{ - return ads_init(NULL, NULL, NULL); + return ads; } /* @@ -117,6 +114,9 @@ void ads_destroy(ADS_STRUCT **ads) { if (ads && *ads) { + BOOL is_mine; + + is_mine = (*ads)->is_mine; #if HAVE_LDAP if ((*ads)->ld) ldap_unbind((*ads)->ld); #endif @@ -133,8 +133,11 @@ SAFE_FREE((*ads)->config.realm); SAFE_FREE((*ads)->config.bind_path); SAFE_FREE((*ads)->config.ldap_server_name); - + + ZERO_STRUCTP(*ads); - SAFE_FREE(*ads); + + if ( is_mine ) + SAFE_FREE(*ads); } } Index: nsswitch/winbindd_ads.c =================================================================== RCS file: /data/cvs/samba/source/nsswitch/winbindd_ads.c,v retrieving revision 1.43.2.37 diff -u -r1.43.2.37 winbindd_ads.c --- nsswitch/winbindd_ads.c 12 Jan 2004 14:26:50 -0000 1.43.2.37 +++ nsswitch/winbindd_ads.c 22 Mar 2004 21:33:01 -0000 @@ -5,6 +5,7 @@ Copyright (C) Andrew Tridgell 2001 Copyright (C) Andrew Bartlett 2003 + Copyright (C) Gerald (Jerry) Carter 2004 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -39,7 +40,21 @@ ADS_STATUS status; if (domain->private) { - return (ADS_STRUCT *)domain->private; + ads = (ADS_STRUCT *)domain->private; + + /* check for a valid structure */ + if ( ads->config.realm ) { + return ads; + } + else { + /* we own this ADS_STRUCT so make sure it goes away */ + ads->is_mine = True; + ads_destroy( &ads ); + + /* we should always be NULL here */ + SMB_ASSERT( ads == NULL ); + } + } /* we don't want this to affect the users ccache */ @@ -78,6 +93,12 @@ } return NULL; } + + /* set the flag that says we don't own the memory even + though we do so that ads_destroy() won't destroy the + structure we pass back by reference */ + + ads->is_mine = False; domain->private = (void *)ads; return ads;