From: sgakerru Date: Sat, 19 Oct 2024 09:26:44 +0000 (+0400) Subject: src/useradd.c: get_groups(): Fix memory leak X-Git-Tag: 4.17.0-rc1~49 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=feead2f639506d49cef9dde385eb56cd3413ecf0;p=thirdparty%2Fshadow.git src/useradd.c: get_groups(): Fix memory leak --- diff --git a/src/useradd.c b/src/useradd.c index 64e7a412e..bd3b0624a 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -760,6 +760,15 @@ static int get_groups (char *list) int errors = 0; int ngroups = 0; + /* + * Free previous group list before creating a new one. + */ + int i = 0; + while (NULL != user_groups[i]) { + free(user_groups[i]); + user_groups[i++] = NULL; + } + if ('\0' == *list) { return 0; }