shadow/backport-src-useradd.c-get_groups-Fix-memory-leak.patch

33 lines
712 B
Diff
Raw Permalink Normal View History

2025-03-11 15:10:16 +08:00
From feead2f639506d49cef9dde385eb56cd3413ecf0 Mon Sep 17 00:00:00 2001
From: sgakerru <sulmpx60@yandex.ru>
Date: Sat, 19 Oct 2024 13:26:44 +0400
Subject: [PATCH] src/useradd.c: get_groups(): Fix memory leak
---
src/useradd.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/useradd.c b/src/useradd.c
index 64e7a412..bd3b0624 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;
}
--
2.33.0