From 8c1e4b96c0cc9deea7c735985237834744dd40dc Mon Sep 17 00:00:00 2001 From: Artem Semenov Date: Mon, 8 Jun 2026 15:34:35 +0300 Subject: [PATCH] fix: memory leak of nsgrp in src/useradd.c grp_update() grp_update() also duplicates each shadow group with __sgr_dup() and never frees the 'nsgrp' copy. Release it with sgr_free(). valgrind --leak-check=full --show-leak-kinds=all \ src/useradd -M -N -G grp1,...,grp10 alice, before this commit: 691 (320 direct, 371 indirect) bytes in 10 blocks are definitely lost at 0x4848EB8: calloc by __sgr_dup (sgroupio.c:37) by grp_update (useradd.c:1104) definitely lost: 480 bytes in 30 blocks after this commit: definitely lost: 160 bytes in 20 blocks Signed-off-by: Artem Semenov Reviewed-by: Alejandro Colomar --- src/useradd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/useradd.c b/src/useradd.c index e243c6857..25b7f4f3c 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -1125,6 +1125,7 @@ static void grp_update (bool process_selinux) #endif SYSLOG(LOG_INFO, "add '%s' to shadow group '%s'", user_name, nsgrp->sg_namp); + sgr_free (nsgrp); } #endif /* SHADOWGRP */ } -- 2.47.3