From 4c765a0e8af22d40a56fc0198a791c6a53f80235 Mon Sep 17 00:00:00 2001 From: Philipp Lopaur Date: Thu, 29 Oct 2026 13:24:18 +0100 Subject: [PATCH] Fix crash when closing one of several map views The footprint scratch buffers were file-level statics shared by all GtkSatMap instances. Every new map reallocated them (leaking the old ones) and destroying any map freed them and set them to NULL, so the remaining maps segfaulted in calculate_footprint() on their next update, e.g. after closing one of two open copies of the same module. Make the buffers per-instance members of GtkSatMap. --- src/gtk-sat-map.c | 33 +++++++++++++++------------------ src/gtk-sat-map.h | 4 ++++ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/gtk-sat-map.c b/src/gtk-sat-map.c index 635c8c24..64d0f8e3 100644 --- a/src/gtk-sat-map.c +++ b/src/gtk-sat-map.c @@ -106,10 +106,6 @@ static sat_map_obj_t *find_sat_at_pos(GtkSatMap * satmap, gfloat mx, gfloat my); static GtkBoxClass *parent_class = NULL; -/* Temporary arrays for footprint calculation */ -static gdouble *temp_points1 = NULL; -static gdouble *temp_points2 = NULL; - /** Convert rgba color to cairo-friendly format */ static void rgba_to_cairo(guint32 rgba, gdouble * r, gdouble * g, gdouble * b, gdouble * a) @@ -256,10 +252,10 @@ static void gtk_sat_map_destroy(GtkWidget * widget) satmap->terminator_count = 0; /* free temporary point arrays */ - g_free(temp_points1); - temp_points1 = NULL; - g_free(temp_points2); - temp_points2 = NULL; + g_free(satmap->temp_points1); + satmap->temp_points1 = NULL; + g_free(satmap->temp_points2); + satmap->temp_points2 = NULL; } (*GTK_WIDGET_CLASS(parent_class)->destroy) (widget); } @@ -394,8 +390,8 @@ GtkWidget *gtk_sat_map_new(GKeyFile * cfgdata, GHashTable * sats, satmap->y0 = 0; /* Allocate temporary point arrays for footprint calculation */ - temp_points1 = g_new0(gdouble, 720); - temp_points2 = g_new0(gdouble, 720); + satmap->temp_points1 = g_new0(gdouble, 720); + satmap->temp_points2 = g_new0(gdouble, 720); /* Connect signals */ gtk_widget_add_events(satmap->canvas, GDK_POINTER_MOTION_MASK | @@ -1426,16 +1422,16 @@ static guint calculate_footprint(GtkSatMap * satmap, sat_t * sat, lonlat_to_xy(satmap, rangelon, rangelat, &sx, &sy); lonlat_to_xy(satmap, mlon, rangelat, &msx, &msy); - temp_points1[2 * azi] = sx; - temp_points1[2 * azi + 1] = sy; + satmap->temp_points1[2 * azi] = sx; + satmap->temp_points1[2 * azi + 1] = sy; - temp_points1[718 - 2 * azi] = msx; - temp_points1[719 - 2 * azi] = msy; + satmap->temp_points1[718 - 2 * azi] = msx; + satmap->temp_points1[719 - 2 * azi] = msy; } if (pole_is_covered(sat)) { - sort_points_x(satmap, sat, temp_points1, 360); + sort_points_x(satmap, sat, satmap->temp_points1, 360); numrc = 1; n1 = 360; n2 = 0; @@ -1445,7 +1441,8 @@ static guint calculate_footprint(GtkSatMap * satmap, sat_t * sat, lonlat_to_xy(satmap, sat->ssplon, sat->ssplat, &ssx, &ssy); n1 = 360; n2 = 360; - split_points(satmap, sat, ssx, temp_points1, &n1, temp_points2, &n2); + split_points(satmap, sat, ssx, satmap->temp_points1, &n1, + satmap->temp_points2, &n2); numrc = 2; } else @@ -1457,14 +1454,14 @@ static guint calculate_footprint(GtkSatMap * satmap, sat_t * sat, g_free(obj->range1_points); obj->range1_points = g_new(gdouble, n1 * 2); - memcpy(obj->range1_points, temp_points1, n1 * 2 * sizeof(gdouble)); + memcpy(obj->range1_points, satmap->temp_points1, n1 * 2 * sizeof(gdouble)); obj->range1_count = n1; if (numrc == 2 && n2 > 0) { g_free(obj->range2_points); obj->range2_points = g_new(gdouble, n2 * 2); - memcpy(obj->range2_points, temp_points2, n2 * 2 * sizeof(gdouble)); + memcpy(obj->range2_points, satmap->temp_points2, n2 * 2 * sizeof(gdouble)); obj->range2_count = n2; } else diff --git a/src/gtk-sat-map.h b/src/gtk-sat-map.h index c19ec557..2dede14c 100644 --- a/src/gtk-sat-map.h +++ b/src/gtk-sat-map.h @@ -99,6 +99,10 @@ typedef struct { gint terminator_count; /*!< Number of terminator points. */ gdouble terminator_last_tstamp; /*!< Timestamp of the last terminator drawn. */ + /* Temporary arrays for footprint calculation */ + gdouble *temp_points1; + gdouble *temp_points2; + gdouble naos; /*!< Next event time. */ gint ncat; /*!< Next event catnum. */