]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
fix: memory leak of ngrp in src/useradd.c grp_update()
authorArtem Semenov <savoptik@altlinux.org>
Thu, 4 Jun 2026 10:45:13 +0000 (13:45 +0300)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Thu, 6 Aug 2026 13:53:48 +0000 (15:53 +0200)
grp_update() duplicates each supplementary group with __gr_dup() to add
the new user, but never frees the 'ngrp' copy.  Release it with
gr_free().

valgrind --leak-check=full --show-leak-kinds=all \
    src/useradd -M -N -G grp1,...,grp10 alice
(the 10 groups already exist), before this commit:

    611 (320 direct, 291 indirect) bytes in 10 blocks are definitely lost
       at 0x4848EB8: calloc
       by __gr_dup (groupmem.c:28)
       by grp_update (useradd.c:1042)
    definitely lost: 800 bytes in 40 blocks

after this commit:

    definitely lost: 480 bytes in 30 blocks

Signed-off-by: Artem Semenov <savoptik@altlinux.org>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
src/useradd.c

index 5404b46c877aabf10d33b4c998b286dd23862950..e243c68570607622ab5903415bc4451c793f8351 100644 (file)
@@ -1063,6 +1063,7 @@ static void grp_update (bool process_selinux)
                              SHADOW_AUDIT_SUCCESS);
 #endif
                SYSLOG(LOG_INFO, "add '%s' to group '%s'", user_name, ngrp->gr_name);
+               gr_free (ngrp);
        }
 
 #ifdef SHADOWGRP