]> git.ipfire.org Git - thirdparty/shadow.git/commit
fix: memory leak of nsgrp in src/useradd.c grp_update() master
authorArtem Semenov <savoptik@altlinux.org>
Mon, 8 Jun 2026 12:34:35 +0000 (15:34 +0300)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Thu, 6 Aug 2026 13:53:48 +0000 (15:53 +0200)
commit8c1e4b96c0cc9deea7c735985237834744dd40dc
treecf265258976d699a5d8e62ea654c11b7f5e9336b
parent58398fb85836f0040aa3b91890bfee506674f27c
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 <savoptik@altlinux.org>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
src/useradd.c