Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PulseAudio OpenStream Memory Leak #968

Open
jaredhagel2 opened this issue Oct 17, 2024 · 5 comments
Open

PulseAudio OpenStream Memory Leak #968

jaredhagel2 opened this issue Oct 17, 2024 · 5 comments
Assignees
Labels
bug Something isn't working src-pulseaudio PulseAudio Host API in src/hostapi/pulseaudio

Comments

@jaredhagel2
Copy link

LeakSanitizer has helped me find a memory leak in the PaPulseAudio_BlockingInitRingBuffer function that is called by OpenStream. This function calls malloc( size ) that is not freed in CloseStream.

To Reproduce

  1. Call Pa_OpenStream
  2. Call Pa_CloseStream
  3. Build program using -fsanitize=address,undefined to point out the memory leak
  4. Run program on Ubuntu 22
  5. When program ends LeakSanitizer states there is leak in pa_linux_pulseaudio.c:960

Expected behavior
There is no leak after program ends.

Actual behavior
LeakSanitizer reports a leak. See attached screenshot.
image

Desktop (please complete the following information):

  • OS: Ubuntu 22
  • PortAudio version: stable, nightly snapshot (which?), current (please give date and/or Git hash):
    Current, git hash - 57aa393
  • If Windows or Linux, which Host API (e.g. WASAPI):
    PulseAudio

Additional context
Add any other context about the problem here.

Note: PortAudio is a community supported project. If you have a solution, please create a Pull Request for us to consider.
I strongly suspect this could be fixed by freeing this memory at the end of PaPulseAudio_CloseStreamCb within pa_linux_pulseaudio_cb.c. If I hear no objection, I'll free this malloc'd memory at this location and test my project. If this works for me I can create a Pull Request with this change. Unfortunately I'm not that familiar with git so this may take some time.

@RossBencina RossBencina added the src-pulseaudio PulseAudio Host API in src/hostapi/pulseaudio label Oct 18, 2024
@RossBencina
Copy link
Collaborator

I strongly suspect this could be fixed by freeing this memory at the end of PaPulseAudio_CloseStreamCb

Given that you are well placed to test the fix, it would be great if you could try the obvious and report back. @illuusio is an active maintainer/developer of that code so they may be able to help.

@illuusio
Copy link
Collaborator

illuusio commented Oct 19, 2024

Thank you for reporting this. Seems that there is something. I don't know (as I'm bit not familiar with ASAN) if this is correct CFLAGS="-fsanitize=address,undefined -static-libasan" cmake -DPA_USE_ALSA=OFF -DPA_USE_OSS=OFF -DPA_USE_JACK=OFF -DPA_BUILD_TESTS=ON .. to make it work? And probably: export LSAN_OPTIONS=verbosity=1:log_threads=1?

@illuusio
Copy link
Collaborator

@RossBencina This drops to Ringbuffer and PaUtilRingBuffer actually. What is the correct way to empty/free it? Is it using PaUtil_FlushRingBuffer at the end?
As the ASAN problem is that in Pulseaudio it reservers ringbuffer but it seams that there should be done something to clean it up but there is no free. As I check the Jack it does not do anything neither to free any resources or I didn't understand it correctly which it the case probably.

@illuusio illuusio added the bug Something isn't working label Oct 19, 2024
@jaredhagel2
Copy link
Author

@RossBencina and @illuusio, I can look at this within the next 1-3 months. It's likely a modestly simple fix, but I'm busy with different projects at the moment. The obvious fix may just work. So, illuusio, I can fix this if you haven't fixed it already by the time I get to it.

@illuusio
Copy link
Collaborator

@RossBencina and @illuusio, I can look at this within the next 1-3 months. It's likely a modestly simple fix, but I'm busy with different projects at the moment. The obvious fix may just work. So, illuusio, I can fix this if you haven't fixed it already by the time I get to it.

It should not be biggies. I'll review if you commit PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working src-pulseaudio PulseAudio Host API in src/hostapi/pulseaudio
Projects
None yet
Development

No branches or pull requests

3 participants