useradd.c:fix memleak in get_groups

Signed-off-by: whzhe <wanghongzhe@huawei.com>
This commit is contained in:
whzhe 2020-12-17 03:27:15 -05:00 committed by whzhe51
parent 599cc003da
commit fd9d79a1a3

View File

@ -793,6 +793,7 @@ static int get_groups (char *list)
fprintf (stderr, fprintf (stderr,
_("%s: group '%s' is a NIS group.\n"), _("%s: group '%s' is a NIS group.\n"),
Prog, grp->gr_name); Prog, grp->gr_name);
gr_free(grp);
continue; continue;
} }
#endif #endif
@ -801,6 +802,7 @@ static int get_groups (char *list)
fprintf (stderr, fprintf (stderr,
_("%s: too many groups specified (max %d).\n"), _("%s: too many groups specified (max %d).\n"),
Prog, ngroups); Prog, ngroups);
gr_free(grp);
break; break;
} }
@ -808,7 +810,7 @@ static int get_groups (char *list)
* Add the group name to the user's list of groups. * Add the group name to the user's list of groups.
*/ */
user_groups[ngroups++] = xstrdup (grp->gr_name); user_groups[ngroups++] = xstrdup (grp->gr_name);
free (grp); gr_free (grp);
} while (NULL != list); } while (NULL != list);
close_group_files (); close_group_files ();