more memory leak fixes
authorAndrew Tridgell <tridge@samba.org>
Wed, 5 Dec 2001 06:26:56 +0000 (06:26 +0000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 5 Dec 2001 06:26:56 +0000 (06:26 +0000)
(This used to be commit eb6f0e91ddd2a97a907a569bc60beca99b494884)

source3/libads/ads_struct.c
source3/libads/ldap.c

index 4227684375e1371868f2b86434dcbabd1c647065..2d8bf061564906ce2ed9c0795d0c3108e3edde7d 100644 (file)
@@ -139,7 +139,7 @@ ADS_STRUCT *ads_init(const char *realm,
        ADS_STRUCT *ads;
        
        ads = (ADS_STRUCT *)smb_xmalloc(sizeof(*ads));
-       memset(ads, 0, sizeof(*ads));
+       ZERO_STRUCTP(ads);
        
        ads->realm = realm? strdup(realm) : NULL;
        ads->ldap_server = ldap_server? strdup(ldap_server) : NULL;
@@ -147,7 +147,7 @@ ADS_STRUCT *ads_init(const char *realm,
        ads->ldap_port = LDAP_PORT;
 
        if (!ads->realm) {
-               ads->realm = lp_realm();
+               ads->realm = strdup(lp_realm());
                if (!ads->realm[0]) {
                        ads->realm = get_default_realm(ads);
                }
@@ -157,7 +157,7 @@ ADS_STRUCT *ads_init(const char *realm,
                ads->bind_path = ads_build_dn(ads->realm);
        }
        if (!ads->ldap_server) {
-               ads->ldap_server = lp_ads_server();
+               ads->ldap_server = strdup(lp_ads_server());
                if (!ads->ldap_server[0]) {
                        ads->ldap_server = find_ldap_server(ads);
                }
@@ -175,7 +175,7 @@ ADS_STRUCT *ads_init(const char *realm,
 */
 void ads_destroy(ADS_STRUCT **ads)
 {
-       if (False && (ads) && (*ads)) {
+       if (ads && *ads) {
                if ((*ads)->ld) ldap_unbind((*ads)->ld);
                SAFE_FREE((*ads)->realm);
                SAFE_FREE((*ads)->ldap_server);
index 34ca2ad04dbdfca00f1eb1954ef6d01148eaffba..251a4a6958b2c6a409fd58ef41817e5a07386c77 100644 (file)
@@ -100,6 +100,14 @@ int ads_search_dn(ADS_STRUCT *ads, void **res,
                             LDAP_SCOPE_BASE, "(objectclass=*)", (char **)attrs, 0, (LDAPMessage **)res);
 }
 
+/*
+  free up memory from a ads_search
+*/
+void ads_msgfree(ADS_STRUCT *ads, void *msg)
+{
+       if (!msg) return;
+       ldap_msgfree(msg);
+}
 
 /*
   find a machine account given a hostname