summaryrefslogtreecommitdiffstats
path: root/source/lib/util_getent.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2001-06-11 19:55:56 +0000
committerJeremy Allison <jra@samba.org>2001-06-11 19:55:56 +0000
commit0f052884b70b7c6ac6957c5fbdb12038d85abc6f (patch)
treeb3e81959ac5f56f5fbf0064a4f17c90d4f49a80f /source/lib/util_getent.c
parentf473c2bd298e4259d4126846ef6bf7d336e6ebd6 (diff)
downloadsamba-0f052884b70b7c6ac6957c5fbdb12038d85abc6f.tar.gz
samba-0f052884b70b7c6ac6957c5fbdb12038d85abc6f.tar.xz
samba-0f052884b70b7c6ac6957c5fbdb12038d85abc6f.zip
Still trying to track down this incredebly intransigent memory free bug...
Jeremy.
Diffstat (limited to 'source/lib/util_getent.c')
-rw-r--r--source/lib/util_getent.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/source/lib/util_getent.c b/source/lib/util_getent.c
index 4123be8e24c..7223cf834d9 100644
--- a/source/lib/util_getent.c
+++ b/source/lib/util_getent.c
@@ -37,14 +37,20 @@ struct sys_grent * getgrent_list(void)
DEBUG (0, ("Out of memory in getgrent_list!\n"));
return NULL;
}
+ memset(gent, '\0', sizeof(struct sys_grent));
glist = gent;
setgrent();
grp = getgrent();
+ if (grp == NULL) {
+ endgrent();
+ free(glist);
+ return NULL;
+ }
+
while (grp != NULL) {
int i,num;
- memset(gent, '\0', sizeof(struct sys_grent));
if (grp->gr_name) {
if ((gent->gr_name = strdup(grp->gr_name)) == NULL)
goto err;
@@ -63,6 +69,8 @@ struct sys_grent * getgrent_list(void)
if ((gent->gr_mem = (char **) malloc(num+1 * sizeof(char *))) == NULL)
goto err;
+ memset(gent->gr_mem, '\0', num+1 * sizeof(char *));
+
for (i=0; i < num; i++) {
if ((gent->gr_mem[i] = strdup(grp->gr_mem[i])) == NULL)
goto err;
@@ -75,6 +83,7 @@ struct sys_grent * getgrent_list(void)
if (gent->next == NULL)
goto err;
gent = gent->next;
+ memset(gent, '\0', sizeof(struct sys_grent));
}
}
@@ -97,7 +106,6 @@ struct sys_grent * getgrent_list(void)
void grent_free (struct sys_grent *glist)
{
while (glist) {
- char **ary;
struct sys_grent *temp;
if (glist->gr_name)
@@ -105,11 +113,9 @@ void grent_free (struct sys_grent *glist)
if (glist->gr_passwd)
free(glist->gr_passwd);
if (glist->gr_mem) {
- ary = glist->gr_mem;
- while (*ary) {
- free(*ary);
- ary++;
- }
+ int i;
+ for (i = 0; glist->gr_mem[i]; i++)
+ free(glist->gr_mem[i]);
free(glist->gr_mem);
}
temp = glist->next;