[alsa-devel] possibly memory leak in alsa-lib

Ivan Sorokin vanyacpp at gmail.com
Mon Oct 29 23:12:55 CET 2012


The following program shows a few leaks in valgrind (ubuntu 12.04, 
alsa-lib 1.0.25, eglibc 2.15):

#include <alsa/asoundlib.h>

int main()
{
     snd_pcm_t* pcm = 0;
     snd_pcm_open(&pcm, "default", SND_PCM_STREAM_PLAYBACK, 0);
     snd_pcm_close(pcm);
     snd_config_update_free_global();
}

Do I close pcm correctly? In file MEMORY-LEAK it is written that program 
should call snd_config_update_free_global() to free global configuration 
cache and I do so.

I'm not sure, but probably some leaks are caused by glibc.
-------------- next part --------------
==3862== Memcheck, a memory error detector
==3862== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==3862== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==3862== Command: ./a.out
==3862== 
==3862== 
==3862== HEAP SUMMARY:
==3862==     in use at exit: 546 bytes in 17 blocks
==3862==   total heap usage: 6,098 allocs, 6,081 frees, 233,541 bytes allocated
==3862== 
==3862== 16 bytes in 1 blocks are indirectly lost in loss record 1 of 17
==3862==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3862==    by 0x5225459: __nss_lookup_function (nsswitch.c:456)
==3862==    by 0x6205184: ???
==3862==    by 0x51DC46C: getgrnam_r@@GLIBC_2.2.5 (getXXbyYY_r.c:256)
==3862==    by 0x51DBAE3: getgrnam (getXXbyYY.c:117)
==3862==    by 0x4EBA4F6: snd1_pcm_direct_parse_open_conf (pcm_direct.c:1614)
==3862==    by 0x4EB3959: _snd_pcm_dmix_open (pcm_dmix.c:1278)
==3862==    by 0x4E7C5E5: snd_pcm_open_conf (pcm.c:2171)
==3862==    by 0x4E7CBBF: snd_pcm_open_noupdate (pcm.c:2225)
==3862==    by 0x4E7EB48: snd1_pcm_open_named_slave (pcm.c:2335)
==3862==    by 0x4EBE4D4: _snd_pcm_softvol_open (pcm_local.h:864)
==3862==    by 0x4E7C5E5: snd_pcm_open_conf (pcm.c:2171)
==3862== 
==3862== 16 bytes in 1 blocks are indirectly lost in loss record 2 of 17
==3862==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3862==    by 0x5225459: __nss_lookup_function (nsswitch.c:456)
==3862==    by 0x620519E: ???
==3862==    by 0x51DC46C: getgrnam_r@@GLIBC_2.2.5 (getXXbyYY_r.c:256)
==3862==    by 0x51DBAE3: getgrnam (getXXbyYY.c:117)
==3862==    by 0x4EBA4F6: snd1_pcm_direct_parse_open_conf (pcm_direct.c:1614)
==3862==    by 0x4EB3959: _snd_pcm_dmix_open (pcm_dmix.c:1278)
==3862==    by 0x4E7C5E5: snd_pcm_open_conf (pcm.c:2171)
==3862==    by 0x4E7CBBF: snd_pcm_open_noupdate (pcm.c:2225)
==3862==    by 0x4E7EB48: snd1_pcm_open_named_slave (pcm.c:2335)
==3862==    by 0x4EBE4D4: _snd_pcm_softvol_open (pcm_local.h:864)
==3862==    by 0x4E7C5E5: snd_pcm_open_conf (pcm.c:2171)
==3862== 
==3862== 16 bytes in 1 blocks are indirectly lost in loss record 3 of 17
==3862==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3862==    by 0x5225459: __nss_lookup_function (nsswitch.c:456)
==3862==    by 0x62051B8: ???
==3862==    by 0x51DC46C: getgrnam_r@@GLIBC_2.2.5 (getXXbyYY_r.c:256)
==3862==    by 0x51DBAE3: getgrnam (getXXbyYY.c:117)
==3862==    by 0x4EBA4F6: snd1_pcm_direct_parse_open_conf (pcm_direct.c:1614)
==3862==    by 0x4EB3959: _snd_pcm_dmix_open (pcm_dmix.c:1278)
==3862==    by 0x4E7C5E5: snd_pcm_open_conf (pcm.c:2171)
==3862==    by 0x4E7CBBF: snd_pcm_open_noupdate (pcm.c:2225)
==3862==    by 0x4E7EB48: snd1_pcm_open_named_slave (pcm.c:2335)
==3862==    by 0x4EBE4D4: _snd_pcm_softvol_open (pcm_local.h:864)
==3862==    by 0x4E7C5E5: snd_pcm_open_conf (pcm.c:2171)
==3862== 
==3862== 16 bytes in 1 blocks are indirectly lost in loss record 4 of 17
==3862==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3862==    by 0x5225459: __nss_lookup_function (nsswitch.c:456)
==3862==    by 0x62051D2: ???
==3862==    by 0x51DC46C: getgrnam_r@@GLIBC_2.2.5 (getXXbyYY_r.c:256)
==3862==    by 0x51DBAE3: getgrnam (getXXbyYY.c:117)
==3862==    by 0x4EBA4F6: snd1_pcm_direct_parse_open_conf (pcm_direct.c:1614)
==3862==    by 0x4EB3959: _snd_pcm_dmix_open (pcm_dmix.c:1278)
==3862==    by 0x4E7C5E5: snd_pcm_open_conf (pcm.c:2171)
==3862==    by 0x4E7CBBF: snd_pcm_open_noupdate (pcm.c:2225)
==3862==    by 0x4E7EB48: snd1_pcm_open_named_slave (pcm.c:2335)
==3862==    by 0x4EBE4D4: _snd_pcm_softvol_open (pcm_local.h:864)
==3862==    by 0x4E7C5E5: snd_pcm_open_conf (pcm.c:2171)
==3862== 
==3862== 16 bytes in 1 blocks are indirectly lost in loss record 5 of 17
==3862==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3862==    by 0x5225459: __nss_lookup_function (nsswitch.c:456)
==3862==    by 0x62051EC: ???
==3862==    by 0x51DC46C: getgrnam_r@@GLIBC_2.2.5 (getXXbyYY_r.c:256)
==3862==    by 0x51DBAE3: getgrnam (getXXbyYY.c:117)
==3862==    by 0x4EBA4F6: snd1_pcm_direct_parse_open_conf (pcm_direct.c:1614)
==3862==    by 0x4EB3959: _snd_pcm_dmix_open (pcm_dmix.c:1278)
==3862==    by 0x4E7C5E5: snd_pcm_open_conf (pcm.c:2171)
==3862==    by 0x4E7CBBF: snd_pcm_open_noupdate (pcm.c:2225)
==3862==    by 0x4E7EB48: snd1_pcm_open_named_slave (pcm.c:2335)
==3862==    by 0x4EBE4D4: _snd_pcm_softvol_open (pcm_local.h:864)
==3862==    by 0x4E7C5E5: snd_pcm_open_conf (pcm.c:2171)
==3862== 
==3862== 19 bytes in 1 blocks are possibly lost in loss record 6 of 17
==3862==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3862==    by 0x51A7D71: strdup (strdup.c:43)
==3862==    by 0x4E65866: snd1_dlobj_cache_get (dlmisc.c:272)
==3862==    by 0x4E7C5C1: snd_pcm_open_conf (pcm.c:2168)
==3862==    by 0x4E7EB8E: snd1_pcm_open_named_slave (pcm.c:2337)
==3862==    by 0x4EA5196: _snd_pcm_empty_open (pcm_empty.c:103)
==3862==    by 0x4E7C5E5: snd_pcm_open_conf (pcm.c:2171)
==3862==    by 0x4E7CBBF: snd_pcm_open_noupdate (pcm.c:2225)
==3862==    by 0x40063E: main (2.cpp:6)
==3862== 
==3862== 19 bytes in 1 blocks are possibly lost in loss record 7 of 17
==3862==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3862==    by 0x51A7D71: strdup (strdup.c:43)
==3862==    by 0x4E65866: snd1_dlobj_cache_get (dlmisc.c:272)
==3862==    by 0x4E7C5C1: snd_pcm_open_conf (pcm.c:2168)
==3862==    by 0x4E7EB8E: snd1_pcm_open_named_slave (pcm.c:2337)
==3862==    by 0x4EBA934: _snd_pcm_asym_open (pcm_asym.c:112)
==3862==    by 0x4E7C5E5: snd_pcm_open_conf (pcm.c:2171)
==3862==    by 0x4E7EB8E: snd1_pcm_open_named_slave (pcm.c:2337)
==3862==    by 0x4EA5196: _snd_pcm_empty_open (pcm_empty.c:103)
==3862==    by 0x4E7C5E5: snd_pcm_open_conf (pcm.c:2171)
==3862==    by 0x4E7CBBF: snd_pcm_open_noupdate (pcm.c:2225)
==3862==    by 0x40063E: main (2.cpp:6)
==3862== 
==3862== 32 bytes in 1 blocks are still reachable in loss record 8 of 17
==3862==    at 0x4C29DB4: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3862==    by 0x57DB59F: _dlerror_run (dlerror.c:142)
==3862==    by 0x57DAFC0: dlopen@@GLIBC_2.2.5 (dlopen.c:88)
==3862==    by 0x4E6562A: snd_dlopen (dlmisc.c:87)
==3862==    by 0x4E60FAB: snd_config_hooks.constprop.26 (conf.c:3310)
==3862==    by 0x4E61A07: snd_config_update_r (conf.c:3768)
==3862==    by 0x4E61E91: snd_config_update (conf.c:3799)
==3862==    by 0x4E7E762: snd_pcm_open (pcm.c:2244)
==3862==    by 0x40063E: main (2.cpp:6)
==3862== 
==3862== 32 bytes in 1 blocks are indirectly lost in loss record 9 of 17
==3862==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3862==    by 0x520FE0A: tsearch (tsearch.c:281)
==3862==    by 0x52253E9: __nss_lookup_function (nsswitch.c:439)
==3862==    by 0x6205184: ???
==3862==    by 0x51DC46C: getgrnam_r@@GLIBC_2.2.5 (getXXbyYY_r.c:256)
==3862==    by 0x51DBAE3: getgrnam (getXXbyYY.c:117)
==3862==    by 0x4EBA4F6: snd1_pcm_direct_parse_open_conf (pcm_direct.c:1614)
==3862==    by 0x4EB3959: _snd_pcm_dmix_open (pcm_dmix.c:1278)
==3862==    by 0x4E7C5E5: snd_pcm_open_conf (pcm.c:2171)
==3862==    by 0x4E7CBBF: snd_pcm_open_noupdate (pcm.c:2225)
==3862==    by 0x4E7EB48: snd1_pcm_open_named_slave (pcm.c:2335)
==3862==    by 0x4EBE4D4: _snd_pcm_softvol_open (pcm_local.h:864)
==3862== 
==3862== 32 bytes in 1 blocks are indirectly lost in loss record 10 of 17
==3862==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3862==    by 0x520FE0A: tsearch (tsearch.c:281)
==3862==    by 0x52253E9: __nss_lookup_function (nsswitch.c:439)
==3862==    by 0x620519E: ???
==3862==    by 0x51DC46C: getgrnam_r@@GLIBC_2.2.5 (getXXbyYY_r.c:256)
==3862==    by 0x51DBAE3: getgrnam (getXXbyYY.c:117)
==3862==    by 0x4EBA4F6: snd1_pcm_direct_parse_open_conf (pcm_direct.c:1614)
==3862==    by 0x4EB3959: _snd_pcm_dmix_open (pcm_dmix.c:1278)
==3862==    by 0x4E7C5E5: snd_pcm_open_conf (pcm.c:2171)
==3862==    by 0x4E7CBBF: snd_pcm_open_noupdate (pcm.c:2225)
==3862==    by 0x4E7EB48: snd1_pcm_open_named_slave (pcm.c:2335)
==3862==    by 0x4EBE4D4: _snd_pcm_softvol_open (pcm_local.h:864)
==3862== 
==3862== 32 bytes in 1 blocks are indirectly lost in loss record 11 of 17
==3862==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3862==    by 0x520FE0A: tsearch (tsearch.c:281)
==3862==    by 0x52253E9: __nss_lookup_function (nsswitch.c:439)
==3862==    by 0x62051B8: ???
==3862==    by 0x51DC46C: getgrnam_r@@GLIBC_2.2.5 (getXXbyYY_r.c:256)
==3862==    by 0x51DBAE3: getgrnam (getXXbyYY.c:117)
==3862==    by 0x4EBA4F6: snd1_pcm_direct_parse_open_conf (pcm_direct.c:1614)
==3862==    by 0x4EB3959: _snd_pcm_dmix_open (pcm_dmix.c:1278)
==3862==    by 0x4E7C5E5: snd_pcm_open_conf (pcm.c:2171)
==3862==    by 0x4E7CBBF: snd_pcm_open_noupdate (pcm.c:2225)
==3862==    by 0x4E7EB48: snd1_pcm_open_named_slave (pcm.c:2335)
==3862==    by 0x4EBE4D4: _snd_pcm_softvol_open (pcm_local.h:864)
==3862== 
==3862== 32 bytes in 1 blocks are indirectly lost in loss record 12 of 17
==3862==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3862==    by 0x520FE0A: tsearch (tsearch.c:281)
==3862==    by 0x52253E9: __nss_lookup_function (nsswitch.c:439)
==3862==    by 0x62051D2: ???
==3862==    by 0x51DC46C: getgrnam_r@@GLIBC_2.2.5 (getXXbyYY_r.c:256)
==3862==    by 0x51DBAE3: getgrnam (getXXbyYY.c:117)
==3862==    by 0x4EBA4F6: snd1_pcm_direct_parse_open_conf (pcm_direct.c:1614)
==3862==    by 0x4EB3959: _snd_pcm_dmix_open (pcm_dmix.c:1278)
==3862==    by 0x4E7C5E5: snd_pcm_open_conf (pcm.c:2171)
==3862==    by 0x4E7CBBF: snd_pcm_open_noupdate (pcm.c:2225)
==3862==    by 0x4E7EB48: snd1_pcm_open_named_slave (pcm.c:2335)
==3862==    by 0x4EBE4D4: _snd_pcm_softvol_open (pcm_local.h:864)
==3862== 
==3862== 32 bytes in 1 blocks are indirectly lost in loss record 13 of 17
==3862==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3862==    by 0x520FE0A: tsearch (tsearch.c:281)
==3862==    by 0x52253E9: __nss_lookup_function (nsswitch.c:439)
==3862==    by 0x62051EC: ???
==3862==    by 0x51DC46C: getgrnam_r@@GLIBC_2.2.5 (getXXbyYY_r.c:256)
==3862==    by 0x51DBAE3: getgrnam (getXXbyYY.c:117)
==3862==    by 0x4EBA4F6: snd1_pcm_direct_parse_open_conf (pcm_direct.c:1614)
==3862==    by 0x4EB3959: _snd_pcm_dmix_open (pcm_dmix.c:1278)
==3862==    by 0x4E7C5E5: snd_pcm_open_conf (pcm.c:2171)
==3862==    by 0x4E7CBBF: snd_pcm_open_noupdate (pcm.c:2225)
==3862==    by 0x4E7EB48: snd1_pcm_open_named_slave (pcm.c:2335)
==3862==    by 0x4EBE4D4: _snd_pcm_softvol_open (pcm_local.h:864)
==3862== 
==3862== 56 bytes in 1 blocks are possibly lost in loss record 14 of 17
==3862==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3862==    by 0x4E65787: snd1_dlobj_cache_get (dlmisc.c:267)
==3862==    by 0x4E7C5C1: snd_pcm_open_conf (pcm.c:2168)
==3862==    by 0x4E7EB8E: snd1_pcm_open_named_slave (pcm.c:2337)
==3862==    by 0x4EA5196: _snd_pcm_empty_open (pcm_empty.c:103)
==3862==    by 0x4E7C5E5: snd_pcm_open_conf (pcm.c:2171)
==3862==    by 0x4E7CBBF: snd_pcm_open_noupdate (pcm.c:2225)
==3862==    by 0x40063E: main (2.cpp:6)
==3862== 
==3862== 56 bytes in 1 blocks are possibly lost in loss record 15 of 17
==3862==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3862==    by 0x4E65787: snd1_dlobj_cache_get (dlmisc.c:267)
==3862==    by 0x4E7C5C1: snd_pcm_open_conf (pcm.c:2168)
==3862==    by 0x4E7EB8E: snd1_pcm_open_named_slave (pcm.c:2337)
==3862==    by 0x4EBA934: _snd_pcm_asym_open (pcm_asym.c:112)
==3862==    by 0x4E7C5E5: snd_pcm_open_conf (pcm.c:2171)
==3862==    by 0x4E7EB8E: snd1_pcm_open_named_slave (pcm.c:2337)
==3862==    by 0x4EA5196: _snd_pcm_empty_open (pcm_empty.c:103)
==3862==    by 0x4E7C5E5: snd_pcm_open_conf (pcm.c:2171)
==3862==    by 0x4E7CBBF: snd_pcm_open_noupdate (pcm.c:2225)
==3862==    by 0x40063E: main (2.cpp:6)
==3862== 
==3862== 64 bytes in 1 blocks are still reachable in loss record 16 of 17
==3862==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3862==    by 0x400EF60: _dl_signal_error (dl-error.c:90)
==3862==    by 0x40151DE: _dl_close (dl-close.c:765)
==3862==    by 0x400F175: _dl_catch_error (dl-error.c:178)
==3862==    by 0x57DB52E: _dlerror_run (dlerror.c:164)
==3862==    by 0x57DB00E: dlclose (dlclose.c:48)
==3862==    by 0x4E65A7E: snd1_dlobj_cache_cleanup (dlmisc.c:321)
==3862==    by 0x4E5DF54: snd_config_update_free_global (conf.c:3842)
==3862==    by 0x40064F: main (2.cpp:8)
==3862== 
==3862== 300 (60 direct, 240 indirect) bytes in 1 blocks are definitely lost in loss record 17 of 17
==3862==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3862==    by 0x5224594: nss_parse_service_list (nsswitch.c:678)
==3862==    by 0x5225055: __nss_database_lookup (nsswitch.c:175)
==3862==    by 0x6205169: ???
==3862==    by 0x51DC46C: getgrnam_r@@GLIBC_2.2.5 (getXXbyYY_r.c:256)
==3862==    by 0x51DBAE3: getgrnam (getXXbyYY.c:117)
==3862==    by 0x4EBA4F6: snd1_pcm_direct_parse_open_conf (pcm_direct.c:1614)
==3862==    by 0x4EB3959: _snd_pcm_dmix_open (pcm_dmix.c:1278)
==3862==    by 0x4E7C5E5: snd_pcm_open_conf (pcm.c:2171)
==3862==    by 0x4E7CBBF: snd_pcm_open_noupdate (pcm.c:2225)
==3862==    by 0x4E7EB48: snd1_pcm_open_named_slave (pcm.c:2335)
==3862==    by 0x4EBE4D4: _snd_pcm_softvol_open (pcm_local.h:864)
==3862== 
==3862== LEAK SUMMARY:
==3862==    definitely lost: 60 bytes in 1 blocks
==3862==    indirectly lost: 240 bytes in 10 blocks
==3862==      possibly lost: 150 bytes in 4 blocks
==3862==    still reachable: 96 bytes in 2 blocks
==3862==         suppressed: 0 bytes in 0 blocks
==3862== 
==3862== For counts of detected and suppressed errors, rerun with: -v
==3862== ERROR SUMMARY: 5 errors from 5 contexts (suppressed: 2 from 2)


More information about the Alsa-devel mailing list