Resource leak in audiosrv triggered by WASAPI backend
Categories
(Core :: Audio/Video: cubeb, defect, P3)
Tracking
()
People
(Reporter: toth.f.janos, Assigned: kinetik)
Details
Updated•7 years ago
|
| Assignee | ||
Comment 1•7 years ago
|
||
| Reporter | ||
Comment 2•7 years ago
|
||
| Reporter | ||
Comment 3•7 years ago
|
||
| Assignee | ||
Comment 4•7 years ago
|
||
| Reporter | ||
Comment 5•7 years ago
|
||
| Reporter | ||
Comment 6•7 years ago
|
||
| Assignee | ||
Comment 7•7 years ago
|
||
I have a similar issue in my program which uses WASAPI. It seems that it is a bug in newer versions of Windows. I can reproduce it on latest Windows 10, but I can't reproduce it on Windows 7.
In my code, the memory leak in the audio service appears on this line:
hr = m_audio_client->Initialize(AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_NOPERSIST, static_cast<UINT64>(m_buffer_size_in_ms) * 10000, 0, m_mix_format, NULL);
The function call returns AUDCLNT_E_DEVICE_IN_USE, but the audio service allocates the requested buffer anyway, and doesn't free it for some reason. So, if you retry to initialize an audio client every second, the audio service will allocate more and more memory for leaked buffers. Apparently, it is a bug in Windows Audio Service itself.
Didn't figure out how to workaround it.
The Windows Audio Service leaks not only memory, but handles also. When you run one program which plays audio in exclusive mode, and another program, which tries to initialize an audio client in shared mode once a second (and of course you release everything properly when it has failed), you will clearly see how amount of handles is increasing using Process Explorer. Process Hacker allows you to see anonymous handles of type Section which are leaked, and their size is exactly the size of buffer which was requested.
I hope that you have some contacts in Microsoft to report them about this bug. It would be really nice if they fix it =)
Comment 10•6 years ago
|
||
A possible workaround: as soon as the audio renderer thread is interrupted, we try to reinitialize immediately, and if we receive AUDCLNT_E_DEVICE_IN_USE, it means that there is an exclusive mode session on the device, so we can enumerate all active sessions on this device (using IAudioSessionEnumerator), there should be just one active session, so we subscribe to their events and wait until OnSessionDisconnected is fired, it will mean that the exclusive session is over, and we can try to initialize our own session again.
Didn't implement it yet, but it seems that it is feasible. It will still leak a buffer (because we try to initialize one time anyway), but won't hurt the system performance as much as now it can.
| Reporter | ||
Comment 11•5 years ago
|
||
The media.cubeb.backend=winmm workaround stopped working with v76.0 (audio and video playback stops working completely with that value, no matter if anything else is using the sound device or not).
Could anyone report this issue in detail to Microsoft in the mean time?
Comment 12•5 years ago
|
||
I reported this bug to Microsoft. It must be fixed in the upcoming Windows 10 version 20H2. Didn't test it yet.
Updated•3 years ago
|
Comment 13•2 years ago
|
||
Seems like the bug is fixed in Windows 11 from its first release, and Microsoft decided to not fix it in Windows 10.
Description
•