From 172cead7fb60b3700ca3aa086712bfb1c24d9fab Mon Sep 17 00:00:00 2001 From: "Andrew V. Samoilov" Date: Tue, 1 Feb 2005 12:04:05 +0000 Subject: [PATCH] * utilunix.c (init_groups): Use glib memory allocation functions. --- src/ChangeLog | 4 ++++ src/utilunix.c | 47 +++++++++++++++++++++++------------------------ 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 261ac1a42..282d4c142 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2005-02-01 Andrew V. Samoilov + + * utilunix.c (init_groups): Use glib memory allocation functions. + 2005-01-31 Roland Illig * view.c: Eliminated two global variables and put them into the diff --git a/src/utilunix.c b/src/utilunix.c index 153321542..2275e2f93 100644 --- a/src/utilunix.c +++ b/src/utilunix.c @@ -94,33 +94,32 @@ void init_groups (void) #ifdef HAVE_GETGROUPLIST { - gid_t *groups = NULL; - int ng = 1; - //struct group *grp; - gid_t *newgroups = NULL; - - groups = (gid_t *) malloc(ng * sizeof(gid_t)); + gid_t *groups = g_new (gid_t, 1); + int ng = 1; + gid_t *newgroups = NULL; - if (getgrouplist(pwd->pw_name, pwd->pw_gid, groups, &ng) == -1) { - newgroups = (gid_t *) malloc(ng * sizeof(gid_t)); - if (newgroups != NULL) { - free (groups); - groups = newgroups; - getgrouplist (pwd->pw_name, pwd->pw_gid, groups, &ng); - } else - ng = 1; - } + if (getgrouplist (pwd->pw_name, pwd->pw_gid, groups, &ng) == -1) { + newgroups = g_new (gid_t, ng); + if (newgroups != NULL) { + g_free (groups); + groups = newgroups; + getgrouplist (pwd->pw_name, pwd->pw_gid, groups, &ng); + } else + ng = 1; + } - for (i = 0; i < ng; i++) { - grp = getgrgid(groups[i]); - if (grp != NULL && !g_tree_lookup (current_user_gid, GUINT_TO_POINTER ((int) grp->gr_gid))) { - g_tree_insert (current_user_gid, - GUINT_TO_POINTER ((int) grp->gr_gid), - g_strdup (grp->gr_name)); - } - } + for (i = 0; i < ng; i++) { + grp = getgrgid (groups[i]); + if (grp != NULL + && !g_tree_lookup (current_user_gid, + GUINT_TO_POINTER ((int) grp->gr_gid))) { + g_tree_insert (current_user_gid, + GUINT_TO_POINTER ((int) grp->gr_gid), + g_strdup (grp->gr_name)); + } + } - free(groups); + g_free (groups); } #else setgrent ();