diff mbox

[FFmpeg-devel] Possible memory leaks in dshow capture

Message ID c547bc23-b01a-3816-723d-f0e6e4b044ff@gmail.com
State New
Headers show

Commit Message

James Almer Jan. 1, 2019, 9:22 p.m. UTC
On 1/1/2019 6:16 PM, Moritz Barsnick wrote:
> 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

Huh, curious, gcc 8 (mingw-w64) compiled this just fine without the
semicolon.
I'm attached a fixed version anyway.

Comments

Moritz Barsnick Jan. 1, 2019, 11:52 p.m. UTC | #1
On Tue, Jan 01, 2019 at 18:22:42 -0300, James Almer wrote:
> >> +    if (!this)
> >> +        return
> >> +    av_freep(&this->imemvtbl);
> > 
> > Do add a semicolon after "return" for good measure. ;)
> 
> Huh, curious, gcc 8 (mingw-w64) compiled this just fine without the
> semicolon.

Oh my. ;-)

"Just fine" means it didn't give you a warning. It produced unintended
code though - unless it additionally optimizes the av_freep() call
away, as libAVPin_Free() is supposed to return void anyway. Obviously
since av_freep() itself produces a void return value, gcc assumes this
is okay. Otherwise, you would have gotten:
warning: ‘return’ with a value, in function returning void

I don't know how to tell gcc to warn about it - except for the funky
new "misleading indentation" warnings.

Sorry for OT...

Moritz
diff mbox

Patch

diff --git a/libavdevice/dshow_pin.c b/libavdevice/dshow_pin.c
index 664246da92..c0f8ec065d 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