diff --git a/libavcodec/g2meet.c b/libavcodec/g2meet.c
index f7a8501ca48503b7827f2b8444a5cddff17b7aa2..43888dc8e382dc5d275681bdba0f98865dfedcc9 100644
--- a/libavcodec/g2meet.c
+++ b/libavcodec/g2meet.c
@@ -455,6 +455,8 @@ static int g2m_init_buffers(G2MContext *c)
         aligned_height = FFALIGN(c->tile_height,    16);
         av_free(c->synth_tile);
         av_free(c->jpeg_tile);
+        av_free(c->kempf_buf);
+        av_free(c->kempf_flags);
         c->synth_tile  = av_mallocz(c->tile_stride      * aligned_height);
         c->jpeg_tile   = av_mallocz(c->tile_stride      * aligned_height);
         c->kempf_buf   = av_mallocz((c->tile_width + 1) * aligned_height