And some more memory leaks in mapping.c and pdb_tdb.c. tdb_nextkey
authorVolker Lendecke <vlendec@samba.org>
Wed, 18 Jun 2003 12:00:52 +0000 (12:00 +0000)
committerVolker Lendecke <vlendec@samba.org>
Wed, 18 Jun 2003 12:00:52 +0000 (12:00 +0000)
mallocs its key, so we should free it after use.

Volker
(This used to be commit 9750799ba2e1aaa59fa255f23880c9c618195c3d)

source3/groupdb/mapping.c
source3/passdb/pdb_tdb.c

index 5b5d0b0cc3f15ee9cd2b79115a3e61ea51105e14..e13730b141f5257b075fb1ef2310a8f64b6bd3df 100644 (file)
@@ -625,6 +625,7 @@ static BOOL get_group_map_from_gid(gid_t gid, GROUP_MAP *map, BOOL with_priv)
                if (gid==map->gid) {
                        if (!with_priv)
                                free_privilege(&map->priv_set);
+                       SAFE_FREE(kbuf.dptr);
                        return True;
                }
                
@@ -692,6 +693,7 @@ static BOOL get_group_map_from_ntname(char *name, GROUP_MAP *map, BOOL with_priv
                if (StrCaseCmp(name, map->nt_name)==0) {
                        if (!with_priv)
                                free_privilege(&map->priv_set);
+                       SAFE_FREE(kbuf.dptr);
                        return True;
                }
 
index d323c20d32d981efc7b5a2a4617e7c2310f9f490..2cf7a0119f3b072e5e9fb1b9fd2da3da995ecf09 100644 (file)
@@ -490,6 +490,7 @@ static void close_tdb(struct tdbsam_privates *tdb_state)
 static void tdbsam_endsampwent(struct pdb_methods *my_methods)
 {
        struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data;
+       SAFE_FREE(tdb_state->key.dptr);
        close_tdb(tdb_state);
        
        DEBUG(7, ("endtdbpwent: closed sam database.\n"));
@@ -503,7 +504,7 @@ static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT *
 {
        NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
        struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data;
-       TDB_DATA        data;
+       TDB_DATA        data, old_key;
        const char *prefix = USERPREFIX;
        int  prefixlen = strlen (prefix);
 
@@ -514,10 +515,16 @@ static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT *
        }
 
        /* skip all non-USER entries (eg. RIDs) */
-       while ((tdb_state->key.dsize != 0) && (strncmp(tdb_state->key.dptr, prefix, prefixlen)))
+       while ((tdb_state->key.dsize != 0) && (strncmp(tdb_state->key.dptr, prefix, prefixlen))) {
+
+               old_key = tdb_state->key;
+
                /* increment to next in line */
                tdb_state->key = tdb_nextkey(tdb_state->passwd_tdb, tdb_state->key);
 
+               SAFE_FREE(old_key.dptr);
+       }
+
        /* do we have an valid iteration pointer? */
        if(tdb_state->passwd_tdb == NULL) {
                DEBUG(0,("pdb_get_sampwent: Bad TDB Context pointer.\n"));
@@ -538,9 +545,13 @@ static NTSTATUS tdbsam_getsampwent(struct pdb_methods *my_methods, SAM_ACCOUNT *
        }
        SAFE_FREE(data.dptr);
        
+       old_key = tdb_state->key;
+       
        /* increment to next in line */
        tdb_state->key = tdb_nextkey(tdb_state->passwd_tdb, tdb_state->key);
 
+       SAFE_FREE(old_key.dptr);
+
        return NT_STATUS_OK;
 }