vlc-3.0.17-win32-0b23c96a leaks 4 handles after playing a local video file
To reproduce the leak just play several times the attached file and you'll see the handles count increase (the same happen on vlc player and in my own app using libvlc). Having a non stop application using libvlc i have more the 2000 handles after 24 hours and mroe than 6000 handles after 3 days.
No problems at all with VLC 3.0.16
the leak occurs also with video and audio disabled so i guess it's something in the core or in the input modules.
the leak only occurs with video files, do not happen with audio files
investing with procexp i see the leaked handles are 2 of type event and 2 of type threads (maybe a thread handle not closed/freed?)
my os win 10 64 bits 21h2
i hope you can investigate and fix this leak before the final realease of 3.0.17
if you mean that leaks are related to Windows SDK i don't think so because the leaks occurs on every windows computer i tried (without Windows SDK installed). You can reproduce the leak easily. 3.0.16 has no problems instead.
You can take the plugins/codec/libavcodec_plugin.dll from the 2021-07-10, put it in the 2021-07-11 build and it should be working as expected. If so that will confirm the issue is with the FFmpeg upgrade.
My point was that the changeset that introduced FFmpeg 4.4 in contribs was the only matching change. That does not necessarily imply that the leak is in FFmpeg as opposed to the VLC code that was changed simultaneously.
There were also some headerd removed but I doubt that's the issue. The issue may be in our code using libavcodec/libavformat and not the contrib code itself.
I confirm that replacing plugins / codec / libavcodec_plugin.dll with that of 2021-07-10 the problem is solved. I also did the same operation with today's night build and also in this case the leak on the handles is gone. So the 4 handle leaks come from plugins / codec / libavcodec_plugin.dll of 11 July 2021 or later.
I confirm this seems related to ffmpeg. If I run with the same configuration (dummy aout/vout, no hw-decoder) with an extra "--codec=faad,none" there's no handle leak anymore. There are leaks with libavcodec is used to decode the video.
There's also no leak when using "--codec=faad,mft" which uses Media Foundation to decode the video.
sorry for the offtopic: I didn't know it was possible to use MediaFoundation codecs. Is it also possible using it with libvlc? i tried passing "--codec=faad,mft" to libvlc_new but i only get a black screen
It turns out that even without the patch it's still picking the old pthreadGC2 implementation from 3.0. And it turns out that's the culprit.
When calling some threading API's from threads that were not created by pthreadGC2 (ie VLC threads) it's creating a fake internal thread object. And the object is never released. It happens twice during each playback.
These events are supposed to be released when pthread_win32_thread_detach_np() and pthread_win32_process_detach_np() are called. It is called during DLL_THREAD_DETACH and DLL_PROCESS_DETACH if pthreadGC2 is compiled in DLL mode. But it's not in our case.
There is a mechanism in static lib that calls these when the process exits. But this is useless in this case.
There are a few possible solutions to fix this:
switch to winpthread from Mingw64 but we need to ensure it works in Windows XP.
build pthreadGC2 as a DLL and ship it next to libvlccore.dll.
hack pthreadGC2 to not create a cancelEvent when called outside of a pthreadGC2 thread, but that means cancelation is not possible on those threads.
disabling all the cancelation API's in pthreadGC2 and see if all the 11 contribs that depend on it build fine. But internally even sem_wait() uses it so we would need to disable it as well.