Subject: Fwd: [PATCH] Fix a memory leak in pgtk_draw_fringe_bitmap

From: Sharaf Zaman <[email-masked]>
Date: Sat, 23 Oct 2021 15:41:00 +0000

Hello!

I discovered that there's a memory leak in the pgtk code, if the windows are
created/destroyed/moved/shrunk/widened frequently. I've verified it with
profiler that this indeed is the location (https://i.imgur.com/LnrgGyj.png) and
fixed it (https://i.imgur.com/zdgnn5K.png).

PS: This is my first time sending a patch over an email, I'm not 100%
sure if this is how it's done.

--
Kind Regards,
Sharaf Zaman
>From 13a901f5e1d6b262ea08e05e95d3e69f99ad4e13 Mon Sep 17 00:00:00 2001
From: Sharaf Zaman <[email-masked]>
Date: Sat, 23 Oct 2021 14:01:55 +0000
Subject: [PATCH] Fix a memory leak in pgtk_draw_fringe_bitmap

* src/pgtkterm.c (pgtk_draw_fringe_bitmap): we had an unbalanced
cairo_save/restore.
---
 src/pgtkterm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/pgtkterm.c b/src/pgtkterm.c
index 86074d010d..40489c0c6b 100644
--- a/src/pgtkterm.c
+++ b/src/pgtkterm.c
@@ -3504,7 +3504,6 @@ pgtk_draw_fringe_bitmap (struct window *w, struct glyph_row *row,
   struct face *face = p->face;
 
   cairo_t *cr = pgtk_begin_cr_clip (f);
-  cairo_save (cr);
 
   /* Must clip because of partially visible lines.  */
   pgtk_clip_to_row (w, row, ANY_AREA, cr);
@@ -3546,7 +3545,7 @@ pgtk_draw_fringe_bitmap (struct window *w, struct glyph_row *row,
 			  p->wd, p->h, p->x, p->y, p->overlay_p);
     }
 
-  cairo_restore (cr);
+  pgtk_end_cr_clip(f);
 }
 
 static struct atimer *hourglass_atimer = NULL;
-- 
2.33.0