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 <git@haasn.dev>
Sponsored-by: nxtedition AB
This commit is contained in:
Niklas Haas
2026-03-25 16:57:58 +01:00
committed by Niklas Haas
parent e7b4ddc9d6
commit 238df21a4f

View File

@@ -1114,6 +1114,8 @@ props_done:
struct pl_render_params tmp_params = opts->params; struct pl_render_params tmp_params = opts->params;
for (int i = 0; i < s->nb_inputs; i++) { for (int i = 0; i < s->nb_inputs; i++) {
LibplaceboInput *in = &s->inputs[i]; LibplaceboInput *in = &s->inputs[i];
if (!in->renderer)
continue; /* input was already freed */
FilterLink *il = ff_filter_link(ctx->inputs[i]); FilterLink *il = ff_filter_link(ctx->inputs[i]);
FilterLink *ol = ff_filter_link(outlink); FilterLink *ol = ff_filter_link(outlink);
int high_fps = av_cmp_q(il->frame_rate, ol->frame_rate) >= 0; 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]; LibplaceboInput *in = &s->inputs[i];
FilterLink *l = ff_filter_link(outlink); FilterLink *l = ff_filter_link(outlink);
if (in->status && out_pts >= in->status_pts) { 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; in->qstatus = PL_QUEUE_EOF;
continue; continue;
} }