diff --git a/src/conio/x_events.c b/src/conio/x_events.c
index 0edc68a7080a5b6146fc59dfbc51a78b4e558e5a..79a6df5977fa9b8980dbb52335bef8dd8ea548be 100644
--- a/src/conio/x_events.c
+++ b/src/conio/x_events.c
@@ -216,6 +216,10 @@ static void resize_xim(void)
 	if (xim) {
 		if (width == xim->width
 		    && height == xim->height) {
+			if (last) {
+				release_buffer(last);
+				last = NULL;
+			}
 			x11.XFillRectangle(dpy, win, gc, 0, 0, x11_window_width, x11_window_height);
 			return;
 		}