PR #22620 opened by Niklas Haas (haasn)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22620
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22620.patch

Otherwise, this will indefinitely persist the last couple of mapped frames
(including any extra decoded frames) in memory, even though they will never be
used again, causing a gradual memory leak until filter uninit.

Signed-off-by: Niklas Haas <[email protected]>
Sponsored-by: nxtedition AB


>From fa1b6160d04bfda05a5d384514bd70a5e44830d8 Mon Sep 17 00:00:00 2001
From: Niklas Haas <[email protected]>
Date: Wed, 25 Mar 2026 16:57:58 +0100
Subject: [PATCH] avfilter/vf_libplacebo: early-free unused resources

Otherwise, this will indefinitely persist the last couple of mapped frames
(including any extra decoded frames) in memory, even though they will never be
used again, causing a gradual memory leak until filter uninit.

Signed-off-by: Niklas Haas <[email protected]>
Sponsored-by: nxtedition AB
---
 libavfilter/vf_libplacebo.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 316eca37ec..b01a2f6eeb 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -1114,6 +1114,8 @@ props_done:
     struct pl_render_params tmp_params = opts->params;
     for (int i = 0; i < s->nb_inputs; i++) {
         LibplaceboInput *in = &s->inputs[i];
+        if (!in->renderer)
+            continue; /* input was already freed */
         FilterLink *il = ff_filter_link(ctx->inputs[i]);
         FilterLink *ol = ff_filter_link(outlink);
         int high_fps = av_cmp_q(il->frame_rate, ol->frame_rate) >= 0;
@@ -1293,6 +1295,9 @@ static int libplacebo_activate(AVFilterContext *ctx)
             LibplaceboInput *in = &s->inputs[i];
             FilterLink *l = ff_filter_link(outlink);
             if (in->status && out_pts >= in->status_pts) {
+                /* Free up resources which will never be needed again */
+                pl_renderer_destroy(&in->renderer);
+                pl_queue_destroy(&in->queue);
                 in->qstatus = PL_QUEUE_EOF;
                 continue;
             }
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to