thestk / rtaudio

A set of C++ classes that provide a common API for realtime audio input/output across Linux (native ALSA, JACK, PulseAudio and OSS), Macintosh OS X (CoreAudio and JACK), and Windows (DirectSound, ASIO, and WASAPI) operating systems.
Other
1.52k stars 322 forks source link

ALSA Memory Leaks #447

Open mttjcksn opened 3 days ago

mttjcksn commented 3 days ago

Hi there,

We have encountered a large number of possible memory leaks reported by valgrind memcheck using the ALSA backend in our application. This can can replicated with the audioprobe and record examples. See the memcheck logs for those test apps:

audioprobe-mem.log record-mem.log

In this note, alsa-project state that not calling snd_config_update_free_global() after all snd_*_open*() calls can lead to leaks. This call frees the global configuration tree and sets snd_config to null, as documented here.

Sure enough, when I edit RtAudio.cpp to ensure that this is done where appropriate, the memcheck logs for audioprobe and record are clean. See below:

audioprobe-mem-fix.log record-mem-fix.log

Has this been addressed before? I can create a PR if required.

Many thanks

garyscavone commented 3 days ago

It would be great if you can submit a PR! We have had some people submit memory leak fixes in the past but it is possible there have been more recent changes to the API that require further updates.

On Nov 27, 2024, at 6:25 AM, mttjcksn @.***> wrote:

Hi there,

We have encountered a large number of possible memory leaks reported by valgrind memcheck using the ALSA backend in our application. This can can replicated with the audioprobe and record examples. See the memcheck logs for those test apps:

audioprobe-mem.loghttps://github.com/user-attachments/files/17932534/audioprobe-mem.log record-mem.loghttps://github.com/user-attachments/files/17932536/record-mem.log

In this notehttps://github.com/alsa-project/alsa-lib/blob/master/MEMORY-LEAK, alsa-project state that not calling snd_config_update_freeglobal() after all snd_open() calls can lead to leaks. This call frees the global configuration tree and sets snd_config to null, as documented herehttps://alsa-project.org/alsa-doc/alsa-lib/group___config.html#ga51dbc0ff1d9b34d753706d09d768116b.

Sure enough, when I edit RtAudio.cpp to ensure that this is done where appropriate, the memcheck logs for audioprobe and record are clean. See below:

audioprobe-mem-fix.loghttps://github.com/user-attachments/files/17932538/audioprobe-mem-fix.log record-mem-fix.loghttps://github.com/user-attachments/files/17932541/record-mem-fix.log

Has this been addressed before? I can create a PR if required.

Many thanks

— Reply to this email directly, view it on GitHubhttps://github.com/thestk/rtaudio/issues/447, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABJYDJLXXG62NQQ5WNFYOFL2CWTZRAVCNFSM6AAAAABSSTMZ2KVHI2DSMVQWIX3LMV43ASLTON2WKOZSGY4TQMJZGQ2TEMY. You are receiving this because you are subscribed to this thread.Message ID: @.***>