[FFmpeg-devel] Possible memory leaks in dshow capture

Submitted by James Almer on Jan. 1, 2019, 8:58 p.m.

Details

Message ID f5e8439f-f941-8951-75d3-ad94b68c5f67@gmail.com
State New
Headers show

Commit Message

James Almer Jan. 1, 2019, 8:58 p.m.
On 1/1/2019 5:01 PM, Oliver Collyer wrote:
> ---------- Block 26224 at 0x0000000074240F70: 151 bytes ----------
>   Leak Hash: 0x357CD5AF, Count: 1, Total 151 bytes
>   Call Stack (TID 55752):
>     ucrtbased.dll!aligned_malloc()
>     c:\ffmpeg\source\ffmpeg\libavutil\mem.c (90): emu-server.exe!av_malloc() + 0x10 bytes
>     c:\ffmpeg\source\ffmpeg\libavdevice\dshow_pin.c (213): emu-server.exe!libAVPin_Setup() + 0xA bytes
>     c:\ffmpeg\source\ffmpeg\libavdevice\dshow_pin.c (252): emu-server.exe!libAVPin_Create() + 0x9B bytes
>     c:\ffmpeg\source\ffmpeg\libavdevice\dshow_filter.c (184): emu-server.exe!libAVFilter_Setup() + 0xA bytes
>     c:\ffmpeg\source\ffmpeg\libavdevice\dshow_filter.c (198): emu-server.exe!libAVFilter_Create() + 0xA8 bytes
>     c:\ffmpeg\source\ffmpeg\libavdevice\dshow.c (809): emu-server.exe!dshow_open_device() + 0x1C bytes
>     c:\ffmpeg\source\ffmpeg\libavdevice\dshow.c (1150): emu-server.exe!dshow_read_header() + 0x18 bytes
>     c:\ffmpeg\source\ffmpeg\libavformat\utils.c (631): emu-server.exe!avformat_open_input() + 0x11 bytes
>     c:\users\oliver\perforce\non-si\emu\shared\dsdevice_streaming_session.cpp (1142): emu-server.exe!DSDEVICE_STREAMING_SESSION::CAPTURE_THREAD::thread_run() + 0x23 bytes
>     c:\users\oliver\perforce\non-si\emu\shared\thread_base.cpp (241): emu-server.exe!THREAD_BASE::thread_func() + 0xE bytes
>     c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\type_traits (16707566): emu-server.exe!std::_Invoker_functor::_Call<int (__cdecl*)(void *),void *>() + 0x2B bytes
>     c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\type_traits (16707566): emu-server.exe!std::invoke<int (__cdecl*)(void *),void *>() + 0x31 bytes
>     c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\thr\xthread (239): emu-server.exe!std::_LaunchPad<std::unique_ptr<std::tuple<int (__cdecl*)(void *),void *>,std::default_delete<std::tuple<int (__cdecl*)(void *),void *> > > >::_Execute<0,1>()
>     c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\thr\xthread (245): emu-server.exe!std::_LaunchPad<std::unique_ptr<std::tuple<int (__cdecl*)(void *),void *>,std::default_delete<std::tuple<int (__cdecl*)(void *),void *> > > >::_Run() + 0x19 bytes
>     c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\thr\xthread (231): emu-server.exe!std::_LaunchPad<std::unique_ptr<std::tuple<int (__cdecl*)(void *),void *>,std::default_delete<std::tuple<int (__cdecl*)(void *),void *> > > >::_Go()
>     c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\thr\xthread (209): emu-server.exe!std::_Pad::_Call_func()
>     ucrtbased.dll!register_onexit_function() + 0x4A8 bytes
>     ucrtbased.dll!register_onexit_function() + 0xE1 bytes
>     KERNEL32.DLL!BaseThreadInitThunk() + 0x14 bytes
>     ntdll.dll!RtlUserThreadStart() + 0x21 bytes
>   Data:
>     70 0F 24 74    46 02 00 00    ED ED ED ED    ED ED ED ED     p.$tF... ........
>     36 DE C8 49    F7 7F 00 00    68 F0 CA 49    F7 7F 00 00     6..I.... h..I....
>     8D 99 CA 49    F7 7F 00 00    1F D6 C9 49    F7 7F 00 00     ...I.... ...I....
>     C9 9E CA 49    F7 7F 00 00    B7 FD C8 49    F7 7F 00 00     ...I.... ...I....
>     22 EC C9 49    F7 7F 00 00    7E E1 C8 49    F7 7F 00 00     "..I.... ~..I....
>     3B 82 CA 49    F7 7F 00 00    CD CD CD CD    CD CD CD CD     ;..I.... ........
>     CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........
>     CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........
>     CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........
>     CD CD CD CD    CD CD CD                                      ........ ........
> 
> 
> ---------- Block 26879 at 0x0000000074242E10: 151 bytes ----------
>   Leak Hash: 0xA886255F, Count: 1, Total 151 bytes
>   Call Stack (TID 55752):
>     ucrtbased.dll!aligned_malloc()
>     c:\ffmpeg\source\ffmpeg\libavutil\mem.c (90): emu-server.exe!av_malloc() + 0x10 bytes
>     c:\ffmpeg\source\ffmpeg\libavdevice\dshow_pin.c (213): emu-server.exe!libAVPin_Setup() + 0xA bytes
>     c:\ffmpeg\source\ffmpeg\libavdevice\dshow_pin.c (252): emu-server.exe!libAVPin_Create() + 0x9B bytes
>     c:\ffmpeg\source\ffmpeg\libavdevice\dshow_filter.c (184): emu-server.exe!libAVFilter_Setup() + 0xA bytes
>     c:\ffmpeg\source\ffmpeg\libavdevice\dshow_filter.c (198): emu-server.exe!libAVFilter_Create() + 0xA8 bytes
>     c:\ffmpeg\source\ffmpeg\libavdevice\dshow.c (809): emu-server.exe!dshow_open_device() + 0x1C bytes
>     c:\ffmpeg\source\ffmpeg\libavdevice\dshow.c (1157): emu-server.exe!dshow_read_header() + 0x1E bytes
>     c:\ffmpeg\source\ffmpeg\libavformat\utils.c (631): emu-server.exe!avformat_open_input() + 0x11 bytes
>     c:\users\oliver\perforce\non-si\emu\shared\dsdevice_streaming_session.cpp (1142): emu-server.exe!DSDEVICE_STREAMING_SESSION::CAPTURE_THREAD::thread_run() + 0x23 bytes
>     c:\users\oliver\perforce\non-si\emu\shared\thread_base.cpp (241): emu-server.exe!THREAD_BASE::thread_func() + 0xE bytes
>     c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\type_traits (16707566): emu-server.exe!std::_Invoker_functor::_Call<int (__cdecl*)(void *),void *>() + 0x2B bytes
>     c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\type_traits (16707566): emu-server.exe!std::invoke<int (__cdecl*)(void *),void *>() + 0x31 bytes
>     c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\thr\xthread (239): emu-server.exe!std::_LaunchPad<std::unique_ptr<std::tuple<int (__cdecl*)(void *),void *>,std::default_delete<std::tuple<int (__cdecl*)(void *),void *> > > >::_Execute<0,1>()
>     c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\thr\xthread (245): emu-server.exe!std::_LaunchPad<std::unique_ptr<std::tuple<int (__cdecl*)(void *),void *>,std::default_delete<std::tuple<int (__cdecl*)(void *),void *> > > >::_Run() + 0x19 bytes
>     c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\thr\xthread (231): emu-server.exe!std::_LaunchPad<std::unique_ptr<std::tuple<int (__cdecl*)(void *),void *>,std::default_delete<std::tuple<int (__cdecl*)(void *),void *> > > >::_Go()
>     c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\thr\xthread (209): emu-server.exe!std::_Pad::_Call_func()
>     ucrtbased.dll!register_onexit_function() + 0x4A8 bytes
>     ucrtbased.dll!register_onexit_function() + 0xE1 bytes
>     KERNEL32.DLL!BaseThreadInitThunk() + 0x14 bytes
>     ntdll.dll!RtlUserThreadStart() + 0x21 bytes
>   Data:
>     CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........
>     CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........
>     10 2E 24 74    46 02 00 00    ED ED ED ED    ED ED ED ED     ..$tF... ........
>     36 DE C8 49    F7 7F 00 00    68 F0 CA 49    F7 7F 00 00     6..I.... h..I....
>     8D 99 CA 49    F7 7F 00 00    1F D6 C9 49    F7 7F 00 00     ...I.... ...I....
>     C9 9E CA 49    F7 7F 00 00    B7 FD C8 49    F7 7F 00 00     ...I.... ...I....
>     22 EC C9 49    F7 7F 00 00    7E E1 C8 49    F7 7F 00 00     "..I.... ~..I....
>     3B 82 CA 49    F7 7F 00 00    CD CD CD CD    CD CD CD CD     ;..I.... ........
>     CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........
>     CD CD CD CD    CD CD CD                                      ........ ........

Does the attached (untested) patch fix these two for you?

Comments

Moritz Barsnick Jan. 1, 2019, 9:16 p.m.
On Tue, Jan 01, 2019 at 17:58:42 -0300, James Almer wrote:
> Does the attached (untested) patch fix these two for you?
[...]
> +    if (!this)
> +        return
> +    av_freep(&this->imemvtbl);

Do add a semicolon after "return" for good measure. ;)

Moritz

Patch hide | download patch | download mbox

diff --git a/libavdevice/dshow_pin.c b/libavdevice/dshow_pin.c
index 664246da92..a4f64ed884 100644
--- a/libavdevice/dshow_pin.c
+++ b/libavdevice/dshow_pin.c
@@ -249,8 +249,16 @@  libAVPin_Setup(libAVPin *this, libAVFilter *filter)

     return 1;
 }
+
+static void
+libAVPin_Free(libAVPin *this)
+{
+    if (!this)
+        return
+    av_freep(&this->imemvtbl);
+}
 DECLARE_CREATE(libAVPin, libAVPin_Setup(this, filter), libAVFilter *filter)
-DECLARE_DESTROY(libAVPin, nothing)
+DECLARE_DESTROY(libAVPin, libAVPin_Free)

 /*****************************************************************************
  * libAVMemInputPin