diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c
index 5f3489505852ece4b3342f71f0e71d6e7a700e33..5a8da27a1692ad0267093677197da9ffb4367aa2 100644
--- a/libavfilter/vf_overlay.c
+++ b/libavfilter/vf_overlay.c
@@ -239,6 +239,7 @@ static int start_frame_overlay(AVFilterLink *inlink, AVFilterBufferRef *inpicref
     OverlayContext *over = ctx->priv;
 
     inlink->cur_buf  = NULL;
+    avfilter_unref_bufferp(&over->overpicref);
     over->overpicref = inpicref;
     over->overpicref->pts = av_rescale_q(inpicref->pts, ctx->inputs[OVERLAY]->time_base,
                                          ctx->outputs[0]->time_base);