[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#273051: Memory leak in libc getpwuid() and getgrouplist()



Package: libc6
Version: 2.3.2.ds1-12

Memory leaks were observed in getpwuid() and getgrouplist().
Two test programs and valgrind output attached.

This is appears to be a bug in nss_compat. After replacing all
occurrences of "compat" with "files" in /etc/nsswitch.conf,
valgrind seems to be happy with the test programs.


getpwuid valgrind output:

==10715== Memcheck, a memory error detector for x86-linux.
==10715== Copyright (C) 2002-2004, and GNU GPL'd, by Julian Seward et al.
==10715== Using valgrind-2.2.0, a program supervision framework for x86-linux.
==10715== Copyright (C) 2000-2004, and GNU GPL'd, by Julian Seward et al.
==10715== 
==10715== My PID = 10715, parent PID = 13663.  Prog and args are:
==10715==    ./getpwuid
==10715== 
==10715== Valgrind library directory: /usr/lib/valgrind
==10715== Command line
==10715==    ./getpwuid
==10715== Startup, with flags:
==10715==    --tool=memcheck
==10715==    -v
==10715==    --leak-resolution=high
==10715==    --leak-check=yes
==10715==    --num-callers=15
==10715==    --trace-children=yes
==10715==    --logfile=valgrind
==10715==    --
==10715== Contents of /proc/version:
==10715==   Linux version 2.6.7 (root@mylly) (gcc version 3.3.3 (Debian 20040401)) #1 Fri Jul 30 10:38:31 EEST 2004
==10715== Reading syms from /home/kihamala/dbus-tmp/getpwuid (0x8048000)
==10715== Reading syms from /lib/ld-2.3.2.so (0x1B8E4000)
==10715==    object doesn't have a symbol table
==10715==    object doesn't have any debug info
==10715== Reading syms from /usr/lib/valgrind/stage2 (0xB0000000)
==10715== Reading syms from /lib/ld-2.3.2.so (0xB1000000)
==10715==    object doesn't have a symbol table
==10715==    object doesn't have any debug info
==10715== Reading syms from /usr/lib/debug/libdl-2.3.2.so (0xB1018000)
==10715== Reading syms from /usr/lib/debug/libc-2.3.2.so (0xB101B000)
==10715== Reading syms from /usr/lib/valgrind/vgskin_memcheck.so (0xB124F000)
==10715== Reading suppressions file: /usr/lib/valgrind/default.supp
==10715== REDIRECT soname:libc.so.6(__GI___errno_location) to soname:libpthread.so.0(__errno_location)
==10715== REDIRECT soname:libc.so.6(__errno_location) to soname:libpthread.so.0(__errno_location)
==10715== REDIRECT soname:libc.so.6(__GI___h_errno_location) to soname:libpthread.so.0(__h_errno_location)
==10715== REDIRECT soname:libc.so.6(__h_errno_location) to soname:libpthread.so.0(__h_errno_location)
==10715== REDIRECT soname:libc.so.6(__GI___res_state) to soname:libpthread.so.0(__res_state)
==10715== REDIRECT soname:libc.so.6(__res_state) to soname:libpthread.so.0(__res_state)
==10715== REDIRECT soname:libc.so.6(stpcpy) to *vgpreload_memcheck.so*(stpcpy)
==10715== REDIRECT soname:libc.so.6(strnlen) to *vgpreload_memcheck.so*(strnlen)
==10715== REDIRECT soname:ld-linux.so.2(stpcpy) to *vgpreload_memcheck.so*(stpcpy)
==10715== REDIRECT soname:ld-linux.so.2(strchr) to *vgpreload_memcheck.so*(strchr)
==10715== 
==10715== Reading syms from /usr/lib/valgrind/vg_inject.so (0x1B8FE000)
==10715== Reading syms from /usr/lib/valgrind/vgpreload_memcheck.so (0x1B901000)
==10715== Reading syms from /usr/lib/debug/libc-2.3.2.so (0x1B90B000)
==10715== TRANSLATE: 0x1B97BDB0 redirected to 0x1B904E4C
==10715== TRANSLATE: 0x1B97BF70 redirected to 0x1B9053DA
==10715== TRANSLATE: 0x1B9825A0 redirected to 0x1B904C30
==10715== TRANSLATE: 0x1B97C5A0 redirected to 0x1B90586A
==10715== Reading syms from /usr/lib/debug/libnss_compat-2.3.2.so (0x1BB40000)
==10715== Reading syms from /usr/lib/debug/libnsl-2.3.2.so (0x1BB49000)
==10715== Reading syms from /usr/lib/debug/libnss_nis-2.3.2.so (0x1BB5F000)
==10715== Reading syms from /usr/lib/debug/libnss_files-2.3.2.so (0x1BB69000)
==10715== discard syms at 0x1BB40000-0x1BB48000 in /usr/lib/debug/libnss_compat-2.3.2.so due to munmap()
==10715== discard syms at 0x1BB5F000-0x1BB68000 in /usr/lib/debug/libnss_nis-2.3.2.so due to munmap()
==10715== discard syms at 0x1BB49000-0x1BB5E000 in /usr/lib/debug/libnsl-2.3.2.so due to munmap()
==10715== discard syms at 0x1BB69000-0x1BB72000 in /usr/lib/debug/libnss_files-2.3.2.so due to munmap()
==10715== 
==10715== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 19 from 1)
--10715-- 
--10715-- supp:   19 Ugly strchr error in /lib/ld-2.3.2.so
==10715== malloc/free: in use at exit: 156 bytes in 11 blocks.
==10715== malloc/free: 65 allocs, 54 frees, 6126 bytes allocated.
==10715== 
==10715== searching for pointers to 11 not-freed blocks.
==10715== checked 1407292 bytes.
==10715== 
==10715== 36 bytes in 1 blocks are definitely lost in loss record 11 of 11
==10715==    at 0x1B904EDD: malloc (vg_replace_malloc.c:131)
==10715==    by 0x1B9F2478: nss_parse_service_list (nsswitch.c:529)
==10715==    by 0x1B9F1CE8: __GI___nss_database_lookup (nsswitch.c:133)
==10715==    by 0x1BB4236B: ???
==10715==    by 0x1BB43F08: ???
==10715==    by 0x1B9B1FF5: getpwuid_r@@GLIBC_2.1.2 (getXXbyYY_r.c:219)
==10715==    by 0x1B9B19FE: getpwuid (getXXbyYY.c:108)
==10715==    by 0x80483AF: main (in /home/kihamala/dbus-tmp/getpwuid)
==10715== 
==10715== LEAK SUMMARY:
==10715==    definitely lost: 36 bytes in 1 blocks.
==10715==    possibly lost:   0 bytes in 0 blocks.
==10715==    still reachable: 120 bytes in 10 blocks.
==10715==         suppressed: 0 bytes in 0 blocks.
==10715== Reachable blocks (those to which a pointer was found) are not shown.
==10715== To see them, rerun with: --show-reachable=yes
--10715--     TT/TC: 0 tc sectors discarded.
--10715--            3200 tt_fast misses.
--10715-- translate: new     3024 (48420 -> 653848; ratio 135:10)
--10715--            discard 208 (2436 -> 34776; ratio 142:10).
--10715-- chainings: 2018 chainings, 0 unchainings.
--10715--  dispatch: 0 jumps (bb entries); of them 9330 (933000%) unchained.
--10715--            58/3465 major/minor sched events.
--10715-- reg-alloc: 565 t-req-spill, 121961+4023 orig+spill uis,
--10715--            15895 total-reg-rank
--10715--    sanity: 59 cheap, 3 expensive checks.
--10715--    ccalls: 11090 C calls, 55% saves+restores avoided (36036 bytes)
--10715--            14734 args, avg 0.86 setup instrs each (3834 bytes)
--10715--            0% clear the stack (33270 bytes)
--10715--            4781 retvals, 31% of reg-reg movs avoided (2900 bytes)

getgrouplist valgrind output:

==10715== Memcheck, a memory error detector for x86-linux.
==10715== Copyright (C) 2002-2004, and GNU GPL'd, by Julian Seward et al.
==10715== Using valgrind-2.2.0, a program supervision framework for x86-linux.
==10715== Copyright (C) 2000-2004, and GNU GPL'd, by Julian Seward et al.
==10715== 
==10715== My PID = 10715, parent PID = 13663.  Prog and args are:
==10715==    ./getpwuid
==10715== 
==10715== Valgrind library directory: /usr/lib/valgrind
==10715== Command line
==10715==    ./getpwuid
==10715== Startup, with flags:
==10715==    --tool=memcheck
==10715==    -v
==10715==    --leak-resolution=high
==10715==    --leak-check=yes
==10715==    --num-callers=15
==10715==    --trace-children=yes
==10715==    --logfile=valgrind
==10715==    --
==10715== Contents of /proc/version:
==10715==   Linux version 2.6.7 (root@mylly) (gcc version 3.3.3 (Debian 20040401)) #1 Fri Jul 30 10:38:31 EEST 2004
==10715== Reading syms from /home/kihamala/dbus-tmp/getpwuid (0x8048000)
==10715== Reading syms from /lib/ld-2.3.2.so (0x1B8E4000)
==10715==    object doesn't have a symbol table
==10715==    object doesn't have any debug info
==10715== Reading syms from /usr/lib/valgrind/stage2 (0xB0000000)
==10715== Reading syms from /lib/ld-2.3.2.so (0xB1000000)
==10715==    object doesn't have a symbol table
==10715==    object doesn't have any debug info
==10715== Reading syms from /usr/lib/debug/libdl-2.3.2.so (0xB1018000)
==10715== Reading syms from /usr/lib/debug/libc-2.3.2.so (0xB101B000)
==10715== Reading syms from /usr/lib/valgrind/vgskin_memcheck.so (0xB124F000)
==10715== Reading suppressions file: /usr/lib/valgrind/default.supp
==10715== REDIRECT soname:libc.so.6(__GI___errno_location) to soname:libpthread.so.0(__errno_location)
==10715== REDIRECT soname:libc.so.6(__errno_location) to soname:libpthread.so.0(__errno_location)
==10715== REDIRECT soname:libc.so.6(__GI___h_errno_location) to soname:libpthread.so.0(__h_errno_location)
==10715== REDIRECT soname:libc.so.6(__h_errno_location) to soname:libpthread.so.0(__h_errno_location)
==10715== REDIRECT soname:libc.so.6(__GI___res_state) to soname:libpthread.so.0(__res_state)
==10715== REDIRECT soname:libc.so.6(__res_state) to soname:libpthread.so.0(__res_state)
==10715== REDIRECT soname:libc.so.6(stpcpy) to *vgpreload_memcheck.so*(stpcpy)
==10715== REDIRECT soname:libc.so.6(strnlen) to *vgpreload_memcheck.so*(strnlen)
==10715== REDIRECT soname:ld-linux.so.2(stpcpy) to *vgpreload_memcheck.so*(stpcpy)
==10715== REDIRECT soname:ld-linux.so.2(strchr) to *vgpreload_memcheck.so*(strchr)
==10715== 
==10715== Reading syms from /usr/lib/valgrind/vg_inject.so (0x1B8FE000)
==10715== Reading syms from /usr/lib/valgrind/vgpreload_memcheck.so (0x1B901000)
==10715== Reading syms from /usr/lib/debug/libc-2.3.2.so (0x1B90B000)
==10715== TRANSLATE: 0x1B97BDB0 redirected to 0x1B904E4C
==10715== TRANSLATE: 0x1B97BF70 redirected to 0x1B9053DA
==10715== TRANSLATE: 0x1B9825A0 redirected to 0x1B904C30
==10715== TRANSLATE: 0x1B97C5A0 redirected to 0x1B90586A
==10715== Reading syms from /usr/lib/debug/libnss_compat-2.3.2.so (0x1BB40000)
==10715== Reading syms from /usr/lib/debug/libnsl-2.3.2.so (0x1BB49000)
==10715== Reading syms from /usr/lib/debug/libnss_nis-2.3.2.so (0x1BB5F000)
==10715== Reading syms from /usr/lib/debug/libnss_files-2.3.2.so (0x1BB69000)
==10715== discard syms at 0x1BB40000-0x1BB48000 in /usr/lib/debug/libnss_compat-2.3.2.so due to munmap()
==10715== discard syms at 0x1BB5F000-0x1BB68000 in /usr/lib/debug/libnss_nis-2.3.2.so due to munmap()
==10715== discard syms at 0x1BB49000-0x1BB5E000 in /usr/lib/debug/libnsl-2.3.2.so due to munmap()
==10715== discard syms at 0x1BB69000-0x1BB72000 in /usr/lib/debug/libnss_files-2.3.2.so due to munmap()
==10715== 
==10715== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 19 from 1)
--10715-- 
--10715-- supp:   19 Ugly strchr error in /lib/ld-2.3.2.so
==10715== malloc/free: in use at exit: 156 bytes in 11 blocks.
==10715== malloc/free: 65 allocs, 54 frees, 6126 bytes allocated.
==10715== 
==10715== searching for pointers to 11 not-freed blocks.
==10715== checked 1407292 bytes.
==10715== 
==10715== 36 bytes in 1 blocks are definitely lost in loss record 11 of 11
==10715==    at 0x1B904EDD: malloc (vg_replace_malloc.c:131)
==10715==    by 0x1B9F2478: nss_parse_service_list (nsswitch.c:529)
==10715==    by 0x1B9F1CE8: __GI___nss_database_lookup (nsswitch.c:133)
==10715==    by 0x1BB4236B: ???
==10715==    by 0x1BB43F08: ???
==10715==    by 0x1B9B1FF5: getpwuid_r@@GLIBC_2.1.2 (getXXbyYY_r.c:219)
==10715==    by 0x1B9B19FE: getpwuid (getXXbyYY.c:108)
==10715==    by 0x80483AF: main (in /home/kihamala/dbus-tmp/getpwuid)
==10715== 
==10715== LEAK SUMMARY:
==10715==    definitely lost: 36 bytes in 1 blocks.
==10715==    possibly lost:   0 bytes in 0 blocks.
==10715==    still reachable: 120 bytes in 10 blocks.
==10715==         suppressed: 0 bytes in 0 blocks.
==10715== Reachable blocks (those to which a pointer was found) are not shown.
==10715== To see them, rerun with: --show-reachable=yes
--10715--     TT/TC: 0 tc sectors discarded.
--10715--            3200 tt_fast misses.
--10715-- translate: new     3024 (48420 -> 653848; ratio 135:10)
--10715--            discard 208 (2436 -> 34776; ratio 142:10).
--10715-- chainings: 2018 chainings, 0 unchainings.
--10715--  dispatch: 0 jumps (bb entries); of them 9330 (933000%) unchained.
--10715--            58/3465 major/minor sched events.
--10715-- reg-alloc: 565 t-req-spill, 121961+4023 orig+spill uis,
--10715--            15895 total-reg-rank
--10715--    sanity: 59 cheap, 3 expensive checks.
--10715--    ccalls: 11090 C calls, 55% saves+restores avoided (36036 bytes)
--10715--            14734 args, avg 0.86 setup instrs each (3834 bytes)
--10715--            0% clear the stack (33270 bytes)
--10715--            4781 retvals, 31% of reg-reg movs avoided (2900 bytes)

Attachment: getpwuid.c
Description: getpwuid.c

Attachment: getgrouplist.c
Description: getgrouplist.c


Reply to: