[mythtv-commits] [MythTV/mythtv] 3d3a2c: Close memory leaks in PulseAudio output handler (#...

Steve Erlenborn noreply at github.com
Sun Jun 1 16:02:50 UTC 2025


  Branch: refs/heads/master
  Home:   https://github.com/MythTV/mythtv
  Commit: 3d3a2cc5fa7c0bb715ab41ab785a76341373b08d
      https://github.com/MythTV/mythtv/commit/3d3a2cc5fa7c0bb715ab41ab785a76341373b08d
  Author: Steve Erlenborn <1751095+SteveErl at users.noreply.github.com>
  Date:   2025-06-01 (Sun, 01 Jun 2025)

  Changed paths:
    M mythtv/libs/libmyth/audio/audiooutputpulse.cpp
    M mythtv/libs/libmyth/audio/audiooutputpulse.h

  Log Message:
  -----------
  Close memory leaks in PulseAudio output handler (#1119)

* Close memory leaks in PulseAudio output handler

The original code allocated memory with calls
to pa_proplist_new(), and stored those addresses
in a local variable, 'proplist'. The corresponding
memory was never released. The same local
variable was used in two different methods,
ContextConnect() and ConnectPlaybackStream().

We need to keep track of these memory pointers
separately, so 2 new members have been added to
the AudioOutputPulseAudio class:
        pa_proplist *m_ctproplist
        pa_proplist *m_stproplist

When memory is allocated for Context or Stream,
the updated code stores the pa_proplist * value
in m_ctproplist or m_stproplist. Later on, when
it's time to release memory, these class members
are used in calls to pa_proplist_free().

A separate memory leak was identified in the call
to pa_context_drain(). This routine allocates
memory which it may need when the drain operation
finishes asynchronously. It is designed to invoke
a callback function when the operation completes.
The original code passed 'nullptr' as the callback
function pointer, but this causes a leak. The
code has been updated to point to a new callback
function, ContextDrainCallback(). If there is
nothing to be drained, we'll disconnect the
Context and drop a reference to it immediately.
If there was stuff to be drained, the new callback
function will disconnect the Context and drop the
reference.

After applying these modifications, all of the
memory leaks associated with audiooutputpulse.cpp
by 'valgrind' have been eliminated.

Resolves: #1100

* Close memory leaks in PulseAudio output handler

Fixing the handling of the pa_context_drain() memory leak.
This update provides a loop to wait for the
ContextDrainCallback() to be invoked before destroying
the reference to the pa_context_drain() operation.
This fixes the memory leak without failing to
disconnect the context.

Resolves #1100

* Close memory leaks in PulseAudio output handler

Adding a check that m_mainloop is non-null before
invoking pa_context_drain(). It is extremely
unlikely that such a circumstance will ever happen.
The lock is only aquired if it is non-null,
and the code for handling pa_context_drain()
requires that the lock be held before calling
pa_threaded_mainloop_wait(), so this small
modification makes the code safer.

Resolves #1100



To unsubscribe from these emails, change your notification settings at https://github.com/MythTV/mythtv/settings/notifications


More information about the mythtv-commits mailing list