From patchwork Wed Jan 2 08:30:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Collyer X-Patchwork-Id: 11632 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 064DE44978C for ; Wed, 2 Jan 2019 10:39:11 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9C67D68A8A6; Wed, 2 Jan 2019 10:39:07 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mr85p00im-zteg06021901.me.com (mr85p00im-zteg06021901.me.com [17.58.23.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B45D468A4F8 for ; Wed, 2 Jan 2019 10:39:00 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mac.com; s=04042017; t=1546417870; bh=6Es124rwlF3LRuNxfXPVJLgdfPsoTAV6UmMMDlm28Xc=; h=From:Content-Type:Mime-Version:Subject:Date:To:Message-Id; b=BIFABIR5D9GzfKn+I4ypk7XgVQzs2gBwUGWk3kSeqgRQRcd5facGi9ArOPV6pwXwe GCsWpiRLVRxp7H3z7KnY+ByBZ0x+w5xZsPj1xedi/KwmSC9crUzdOpKwRZw1iUg7ps 4qM90LmO2EikbnYAe3vtmdnH+RUapFcZGdyNC/UaNd8+oiY+kNpU1ehlGUpaLFGlIR pv8EgkJ6P/ghx3HUEAEeOaLEvigucLhGP8vWwN+pScJ6I0hrth8KVfZp9vSFIDIrir FaUPaLrEYKntGWtAqeLr1zejjMUEhfcENmLV33HC2FilCdNTuoKkvZp4EHpX79anjq GkiZx/yx0tmbg== Received: from [10.143.175.115] (air143.wispotter.com [212.2.212.143]) by mr85p00im-zteg06021901.me.com (Postfix) with ESMTPSA id 4095472018A for ; Wed, 2 Jan 2019 08:31:03 +0000 (UTC) From: Oliver Collyer Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Date: Wed, 2 Jan 2019 11:30:43 +0300 References: <54FC7158-A35F-41FE-AA48-4C0D66AFB456@mac.com> To: FFmpeg development discussions and patches In-Reply-To: Message-Id: <21543D43-DD7F-4BB0-91CE-BD85CDBCAE90@mac.com> X-Mailer: Apple Mail (2.3445.102.3) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-01-02_02:, , signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 mlxscore=0 mlxlogscore=976 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1901020078 Subject: Re: [FFmpeg-devel] Possible memory leaks in dshow capture X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" > On 1 Jan 2019, at 23:58, James Almer wrote: > > 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() + 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() + 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::default_delete > > >::_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::default_delete > > >::_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::default_delete > > >::_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() + 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() + 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::default_delete > > >::_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::default_delete > > >::_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::default_delete > > >::_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? Yes it does, thank you. I've worked through the others, and here is a patch that fixes them. ====== diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 25481580af..ac05ab6cdb 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -278,12 +278,12 @@ dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum, goto fail1; } *device_unique_name = unique_name; + unique_name = NULL; // success, loop will end now } } else { av_log(avctx, AV_LOG_INFO, " \"%s\"\n", friendly_name); av_log(avctx, AV_LOG_INFO, " Alternative name \"%s\"\n", unique_name); - av_free(unique_name); } fail1: @@ -291,8 +291,9 @@ fail1: IMalloc_Free(co_malloc, olestr); if (bind_ctx) IBindCtx_Release(bind_ctx); - av_free(friendly_name); - if (bag) + av_freep(&friendly_name); + av_freep(&unique_name); + if (bag) IPropertyBag_Release(bag); IMoniker_Release(m); } @@ -941,6 +942,8 @@ dshow_add_device(AVFormatContext *avctx, AVStream *st; int ret = AVERROR(EIO); + type.pbFormat = NULL; + st = avformat_new_stream(avctx, NULL); if (!st) { ret = AVERROR(ENOMEM); @@ -989,7 +992,8 @@ dshow_add_device(AVFormatContext *avctx, if (par->codec_id == AV_CODEC_ID_NONE) { av_log(avctx, AV_LOG_ERROR, "Unknown compression type. " "Please report type 0x%X.\n", (int) bih->biCompression); - return AVERROR_PATCHWELCOME; + ret = AVERROR_PATCHWELCOME; + goto error; } par->bits_per_coded_sample = bih->biBitCount; } else { @@ -1030,6 +1034,8 @@ dshow_add_device(AVFormatContext *avctx, ret = 0; error: +. if (type.pbFormat) +. CoTaskMemFree(type.pbFormat); return ret; } diff --git a/libavdevice/dshow_pin.c b/libavdevice/dshow_pin.c index 664246da92..12e508bf01 100644 --- a/libavdevice/dshow_pin.c +++ b/libavdevice/dshow_pin.c @@ -249,8 +249,20 @@ libAVPin_Setup(libAVPin *this, libAVFilter *filter) return 1; } + +static void +libAVPin_Free(libAVPin *this) +{ + if (!this) + return; + av_freep(&this->imemvtbl); + if (this->type.pbFormat) { + CoTaskMemFree(this->type.pbFormat); + this->type.pbFormat = NULL; + } +} DECLARE_CREATE(libAVPin, libAVPin_Setup(this, filter), libAVFilter *filter) -DECLARE_DESTROY(libAVPin, nothing) +DECLARE_DESTROY(libAVPin, libAVPin_Free) /***************************************************************************** * libAVMemInputPin