[PATCH 05/18] libaf/af_lavcac3enc: properly free codec context

Nicolas George <[email protected]> Tue, 28 Jul 2026 20:15:01 +0200
Newsgroups gmane.comp.video.mplayer.devel
Message-ID <[email protected]>
---
 libaf/af_lavcac3enc.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/libaf/af_lavcac3enc.c b/libaf/af_lavcac3enc.c
index 9c8b6eec8..99407daa0 100644
--- a/libaf/af_lavcac3enc.c
+++ b/libaf/af_lavcac3enc.c
@@ -100,8 +100,14 @@ static int control(struct af_instance_s *af, int cmd, void *arg)
                 s->lavc_actx->sample_rate != af->data->rate ||
                 s->lavc_actx->bit_rate != bit_rate) {
 
-            if (s->lavc_actx->codec)
-                avcodec_close(s->lavc_actx);
+            if (s->lavc_actx->codec) {
+                avcodec_free_context(&s->lavc_actx);
+                s->lavc_actx = avcodec_alloc_context3(NULL);
+                if (!s->lavc_actx) {
+                    mp_msg(MSGT_AFILTER, MSGL_ERR, MSGTR_CouldntAllocateLavcContext);
+                    return AF_ERROR;
+                }
+            }
 
             // Put sample parameters
             s->lavc_actx->ch_layout.nb_channels = af->data->nch;
@@ -156,11 +162,7 @@ static void uninit(struct af_instance_s* af)
     if (af->setup) {
         af_ac3enc_t *s = af->setup;
         af->setup = NULL;
-        if(s->lavc_actx) {
-            if (s->lavc_actx->codec)
-                avcodec_close(s->lavc_actx);
-            free(s->lavc_actx);
-        }
+        avcodec_free_context(&s->lavc_actx);
         free(s->pending_data);
         free(s);
     }
-- 
2.53.0

_______________________________________________
MPlayer-dev-eng mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo/%(_internal_name)s