]> git.sesse.net Git - ffmpeg/commitdiff
lavc/libopusdec: Allow avcodec_open2 to call .close
authorMatt Wolenetz <wolenetz@google.com>
Tue, 10 Apr 2018 20:59:25 +0000 (13:59 -0700)
committerMichael Niedermayer <michael@niedermayer.cc>
Wed, 11 Apr 2018 00:42:41 +0000 (02:42 +0200)
If there is a decoder initialization failure detected in avcodec_open2
after .init is called, allow graceful decoder .close to prevent leaking
libopus decoder allocations.

BUG=828526

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavcodec/libopusdec.c

index 3d2ee5b61b21b0234fdbee8b45a2a80d4562ecd1..2a97811d187cf725593670175298a3d272df4e80 100644 (file)
@@ -160,7 +160,10 @@ static av_cold int libopus_decode_close(AVCodecContext *avc)
 {
     struct libopus_context *opus = avc->priv_data;
 
-    opus_multistream_decoder_destroy(opus->dec);
+    if (opus->dec) {
+        opus_multistream_decoder_destroy(opus->dec);
+        opus->dec = NULL;
+    }
     return 0;
 }
 
@@ -252,6 +255,7 @@ AVCodec ff_libopus_decoder = {
     .decode         = libopus_decode,
     .flush          = libopus_flush,
     .capabilities   = AV_CODEC_CAP_DR1,
+    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
     .sample_fmts    = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLT,
                                                      AV_SAMPLE_FMT_S16,
                                                      AV_SAMPLE_FMT_NONE },