October 22, 2024
Chicago 12, Melborne City, USA
C++

ALSA snd_device_name_hint memory leak?


Is it ok that the following code:

#include <alsa/asoundlib.h>

int main(void)
{
    void **hints;
    if (snd_device_name_hint(-1, "pcm", &hints) < 0) {
        return -1;
    }
    if (snd_device_name_free_hint(hints) < 0) {
        return -1;
    }
    if (snd_config_update_free_global() < 0) {
        return -1;
    }
    printf("Ok");
    return 0;
}

exits with 0 and makes Valgrind return "still reachable: 65,368 bytes in 131 blocks"?

I know what "still reachable" means and that someone deems it acceptable in some context. I just want to be sure that I am using the ALSA library properly and it is not depending on my side.

Configuration:
Ubuntu 22.04.5, libasound2:amd64 1.2.6.1-1ubuntu1 amd64, valgrind-3.18.1, Ubuntu GLIBC 2.35-0ubuntu3.8.

These are the first lines of Valgrind output:

==33979== Memcheck, a memory error detector
==33979== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==33979== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==33979== Command: /home/pippo/test_pcm_device_information
==33979== 
Ok==33979== 
==33979== HEAP SUMMARY:
==33979==     in use at exit: 65,368 bytes in 131 blocks
==33979==   total heap usage: 46,998 allocs, 46,867 frees, 1,974,997 bytes allocated
==33979== 
==33979== 4 bytes in 1 blocks are still reachable in loss record 1 of 37
==33979==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==33979==    by 0x510895A: pa_xmalloc (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-15.99.so)
==33979==    by 0x51448E7: pa_tls_new (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-15.99.so)
==33979==    by 0x5114FC3: ??? (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-15.99.so)
==33979==    by 0x512B8C4: pa_run_once (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-15.99.so)
==33979==    by 0x5115068: pa_cstrerror (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-15.99.so)
==33979==    by 0x510F6D1: pa_config_parse (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-15.99.so)
==33979==    by 0x510F7EC: pa_config_parse (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-15.99.so)
==33979==    by 0x510FE0A: pa_client_conf_load (in /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-15.99.so)
==33979==    by 0x50AA5D9: pa_context_new_with_proplist (in /usr/lib/x86_64-linux-gnu/libpulse.so.0.24.1)
==33979==    by 0x485C2B6: ???
==33979==    by 0x48C418D: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==33979==    by 0x48C466C: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==33979==    by 0x48C4770: snd_config_searcha_hooks (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==33979==    by 0x48C48B0: snd_config_searchva_hooks (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==33979==    by 0x48C49B2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==33979==    by 0x48C4C62: snd_config_search_definition (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==33979==    by 0x4925010: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==33979==    by 0x4926236: snd_device_name_hint (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==33979==    by 0x1091FE: main (test_pcm_device_information.c:6)
==33979== 
{
   <insert_a_suppression_name_here>
   Memcheck:Leak
   match-leak-kinds: reachable
   fun:malloc
   fun:pa_xmalloc
   fun:pa_tls_new
   obj:/usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-15.99.so
   fun:pa_run_once
   fun:pa_cstrerror
   fun:pa_config_parse
   fun:pa_config_parse
   fun:pa_client_conf_load
   fun:pa_context_new_with_proplist
   obj:*
   obj:/usr/lib/x86_64-linux-gnu/libasound.so.2.0.0
   obj:/usr/lib/x86_64-linux-gnu/libasound.so.2.0.0
   fun:snd_config_searcha_hooks
   fun:snd_config_searchva_hooks
   obj:/usr/lib/x86_64-linux-gnu/libasound.so.2.0.0
   fun:snd_config_search_definition
   obj:/usr/lib/x86_64-linux-gnu/libasound.so.2.0.0
   fun:snd_device_name_hint
   fun:main
}



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video