]> granicus.if.org Git - handbrake/commitdiff
FFMPEG: Use avcodec_free_context(..) instead of deprecated leaking avcodec_close(..)
authorSven Gothel <sgothel@jausoft.com>
Fri, 12 Jan 2018 00:53:01 +0000 (01:53 +0100)
committerBradley Sepos <bradley@bradleysepos.com>
Tue, 29 May 2018 03:56:19 +0000 (23:56 -0400)
Hence rename hb_avcodec_close -> hb_avcodec_free_context and pass the required ptr-ptr.
avcodec_free_context(..) ensures releasing of all resources attached to the context.

libhb/decavcodec.c
libhb/decpgssub.c
libhb/encavcodec.c
libhb/encavcodecaudio.c
libhb/hb.c
libhb/hbffmpeg.h

index f12e20df505bf0a2554ebdf60a7a93cc2aaec22e..26430dce4a90ada49db553d619c6e00627cbb6af 100644 (file)
@@ -390,13 +390,12 @@ static void closePrivData( hb_work_private_t ** ppv )
             //if (!(pv->qsv.decode && pv->job != NULL && (pv->job->vcodec & HB_VCODEC_QSV_MASK)))
 #endif
             {
-                hb_avcodec_close(pv->context);
+                hb_avcodec_free_context(&pv->context);
             }
         }
         if ( pv->context )
         {
-            av_freep( &pv->context->extradata );
-            av_freep( &pv->context );
+            hb_avcodec_free_context(&pv->context);
         }
         hb_audio_resample_free(pv->resample);
 
@@ -821,9 +820,7 @@ static int decavcodecaBSInfo( hb_work_object_t *w, const hb_buffer_t *buf,
 
     if ( parser != NULL )
         av_parser_close( parser );
-    hb_avcodec_close( context );
-    av_freep( &context->extradata );
-    av_freep( &context );
+    hb_avcodec_free_context(&context);
     return result;
 }
 
@@ -2105,9 +2102,7 @@ static void decavcodecvFlush( hb_work_object_t *w )
         if ( pv->title->opaque_priv == NULL )
         {
             pv->video_codec_opened = 0;
-            hb_avcodec_close( pv->context );
-            av_freep( &pv->context->extradata );
-            av_freep( &pv->context );
+            hb_avcodec_free_context(&pv->context);
             if ( pv->parser )
             {
                 av_parser_close(pv->parser);
index e4c22d20630628e6abbd35bbfcb4fe80f54c23ac..acb0e1dde4e21943442e28815525d4777d290942 100644 (file)
@@ -502,7 +502,7 @@ static void decsubClose( hb_work_object_t * w )
 {
     hb_work_private_t * pv = w->private_data;
     avcodec_flush_buffers( pv->context );
-    avcodec_close( pv->context );
+    avcodec_free_context( &pv->context );
 }
 
 hb_work_object_t hb_decpgssub =
index 01a1fc38954960e71983517db51c51f3ef5f0819..8484bba6a0cc442bf704b99320361a26cc72726e 100644 (file)
@@ -399,12 +399,13 @@ void encavcodecClose( hb_work_object_t * w )
         return;
     }
     hb_chapter_queue_close(&pv->chapter_queue);
-    if( pv->context && pv->context->codec )
+    if( pv->context )
     {
         hb_deep_log( 2, "encavcodec: closing libavcodec" );
-        avcodec_flush_buffers( pv->context );
-        hb_avcodec_close( pv->context );
-        av_free( pv->context );
+        if( pv->context->codec ) {
+            avcodec_flush_buffers( pv->context );
+        }
+        hb_avcodec_free_context(&pv->context);
     }
     if( pv->file )
     {
index 79f775a9dc845ada5e994a898f334769e682b3dd..d3c1fe5d13773bbf57066ee109ec8f3aaddd17e7 100644 (file)
@@ -308,10 +308,10 @@ static void encavcodecaClose(hb_work_object_t * w)
         {
             Finalize(w);
             hb_deep_log(2, "encavcodecaudio: closing libavcodec");
-            if (pv->context->codec != NULL)
+            if (pv->context->codec != NULL) {
                 avcodec_flush_buffers(pv->context);
-            hb_avcodec_close(pv->context);
-            av_free( pv->context );
+            }
+            hb_avcodec_free_context(&pv->context);
         }
 
         if (pv->output_buf != NULL)
index b973645b009497229c35f5b246bf0c177a9b7879..a0d1b7291e8e966d4f1898d82e73fa8a49d3ad39 100644 (file)
@@ -140,11 +140,9 @@ int hb_avcodec_open(AVCodecContext *avctx, AVCodec *codec,
     return ret;
 }
 
-int hb_avcodec_close(AVCodecContext *avctx)
+void hb_avcodec_free_context(AVCodecContext **avctx)
 {
-    int ret;
-    ret = avcodec_close(avctx);
-    return ret;
+    avcodec_free_context(avctx);
 }
 
 
index c27f1f3d0fff2d6e5a2fa13d140d00a5bbefd9f3..890b62ffc909192586a5d3fcc942974e4d5a2664 100644 (file)
@@ -24,7 +24,7 @@
 
 void hb_avcodec_init(void);
 int  hb_avcodec_open(AVCodecContext *, AVCodec *, AVDictionary **, int);
-int  hb_avcodec_close(AVCodecContext *);
+void hb_avcodec_free_context(AVCodecContext **avctx);
 const char* const* hb_av_preset_get_names(int encoder);
 
 uint64_t hb_ff_mixdown_xlat(int hb_mixdown, int *downmix_mode);