From ddfb4d4f739dcdc79561d8db76bd929e1442e7cd Mon Sep 17 00:00:00 2001 From: Alx Sa Date: Thu, 8 Aug 2024 04:27:46 +0000 Subject: [PATCH] plug-ins: Fix crash when editing Gradient Flare As Lloyd Konneker noted, the calc.sflare_list was not being accessed at the right location when the Edit Dialog preview of the gradient was updated. The API page for g_list_free_full () recommends using g_steal_pointer () to ensure the head element is not left dangling. This aligns with other usage in the GIMP codebase and seems to stop the crash. Additional safety checks were also added. --- plug-ins/gradient-flare/gradient-flare.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/plug-ins/gradient-flare/gradient-flare.c b/plug-ins/gradient-flare/gradient-flare.c index 2b4104cfbc..0fb2c81a73 100644 --- a/plug-ins/gradient-flare/gradient-flare.c +++ b/plug-ins/gradient-flare/gradient-flare.c @@ -2109,7 +2109,8 @@ calc_deinit (void) return; } - g_list_free_full (calc.sflare_list, (GDestroyNotify) g_free); + g_list_free_full (g_steal_pointer (&calc.sflare_list), (GDestroyNotify) g_free); + calc.sflare_list = NULL; g_free (calc.glow_radial); g_free (calc.glow_angular); @@ -2276,7 +2277,10 @@ calc_rays_pix (guchar *dest_pix, gdouble x, gdouble y) * glow, rays は簡易化のためになし。 */ void -calc_sflare_pix (guchar *dest_pix, gdouble x, gdouble y, guchar *src_pix) +calc_sflare_pix (guchar *dest_pix, + gdouble x, + gdouble y, + guchar *src_pix) { GList *list; CalcSFlare *sflare; @@ -2290,11 +2294,15 @@ calc_sflare_pix (guchar *dest_pix, gdouble x, gdouble y, guchar *src_pix) return; list = calc.sflare_list; + while (list) { sflare = list->data; list = list->next; + if (! sflare) + break; + if (x < sflare->bounds.x0 || x > sflare->bounds.x1 || y < sflare->bounds.y0 || y > sflare->bounds.y1) continue; @@ -2862,7 +2870,7 @@ dlg_preview_deinit_func (Preview *preview, gpointer data) if (dlg->init_params_done) { calc_deinit (); - dlg->init_params_done = TRUE; + dlg->init_params_done = FALSE; } }