]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
src/useradd.c: get_groups(): Fix memory leak
authorsgakerru <sulmpx60@yandex.ru>
Sat, 19 Oct 2024 09:26:44 +0000 (13:26 +0400)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Wed, 30 Oct 2024 11:58:55 +0000 (12:58 +0100)
src/useradd.c

index 64e7a412eed15a6a750386056823d06077c74e48..bd3b0624a655982dd36221ca597d949a899a01eb 100644 (file)
@@ -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;
        }