From: Artem Semenov Date: Thu, 4 Jun 2026 11:04:03 +0000 (+0300) Subject: fix: memory leak of ngrp in src/userdel.c update_groups() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3ebf0c2210ff2df095dc1835a7a86c6bf8ac5b6;p=thirdparty%2Fshadow.git fix: memory leak of ngrp in src/userdel.c update_groups() Likewise, update_groups() duplicates each regular group with __gr_dup() and never frees the 'ngrp' copy. Release it with gr_free(); as with __sgr_dup(), the duplicate owns deep-copied fields, so free() alone would leak them. valgrind --leak-check=full --show-leak-kinds=all src/userdel -P bob, before this commit: 471 (320 direct, 151 indirect) bytes in 10 blocks are definitely lost at 0x4848EB8: calloc by __gr_dup (groupmem.c:28) by update_groups (userdel.c:197) definitely lost: 800 bytes in 40 blocks after this commit: definitely lost: 480 bytes in 30 blocks Signed-off-by: Artem Semenov Reviewed-by: Alejandro Colomar --- diff --git a/src/userdel.c b/src/userdel.c index 5e7cf38eb..06b44e9e6 100644 --- a/src/userdel.c +++ b/src/userdel.c @@ -219,6 +219,7 @@ static void update_groups (bool process_selinux) #endif /* WITH_AUDIT */ SYSLOG(LOG_INFO, "delete '%s' from group '%s'\n", user_name, ngrp->gr_name); + gr_free (ngrp); } if (getdef_bool ("USERGROUPS_ENAB")) {