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>
SHADOW_AUDIT_SUCCESS);
#endif
SYSLOG(LOG_INFO, "add '%s' to group '%s'", user_name, ngrp->gr_name);
+ gr_free (ngrp);
}
#ifdef SHADOWGRP