From d9c674e05188abe16dc9440a8c1597632982dd48 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sat, 27 Jun 2020 18:00:16 +0200 Subject: [PATCH] Fix bug #54784 (again). Certain GUI entities hold pointers to variables. To ensure that the variables survive the lifetime of the entity which holds the pointer, the entity must take a reference. This is particularly important where a transformation which involves TEMPORARY of a filter is involved. --- src/ui/gui/psppire-dialog-action-indep-samps.c | 9 +++++++-- src/ui/gui/psppire-dialog-action-indep-samps.h | 2 +- src/ui/gui/psppire-var-ptr.c | 6 +++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/ui/gui/psppire-dialog-action-indep-samps.c b/src/ui/gui/psppire-dialog-action-indep-samps.c index faea2b4141..f0995e92e8 100644 --- a/src/ui/gui/psppire-dialog-action-indep-samps.c +++ b/src/ui/gui/psppire-dialog-action-indep-samps.c @@ -74,6 +74,7 @@ refresh (PsppireDialogAction *da) value_destroy (&act->cut_point, width); value_destroy (&act->grp_val[0], width); value_destroy (&act->grp_val[1], width); + var_unref (act->grp_var); act->grp_var = NULL; act->grp_var_width = -1; } @@ -243,7 +244,7 @@ on_grp_var_change (GtkEntry *entry, PsppireDialogActionIndepSamps *act) PsppireDialogAction *da = PSPPIRE_DIALOG_ACTION (act); const gchar *text = gtk_entry_get_text (entry); - const struct variable *v = da->dict ? psppire_dict_lookup_var (da->dict, text) : NULL; + struct variable *v = da->dict ? psppire_dict_lookup_var (da->dict, text) : NULL; gtk_widget_set_sensitive (act->define_groups_button, v != NULL); @@ -276,7 +277,11 @@ on_grp_var_change (GtkEntry *entry, PsppireDialogActionIndepSamps *act) } } - act->grp_var = v; + struct variable *old_grp_var = act->grp_var; + if (v) + act->grp_var = var_ref (v); + if (old_grp_var) + var_unref (old_grp_var); act->grp_var_width = v ? var_get_width (v) : -1; } diff --git a/src/ui/gui/psppire-dialog-action-indep-samps.h b/src/ui/gui/psppire-dialog-action-indep-samps.h index 672a403074..e6ae0aaef0 100644 --- a/src/ui/gui/psppire-dialog-action-indep-samps.h +++ b/src/ui/gui/psppire-dialog-action-indep-samps.h @@ -75,7 +75,7 @@ struct _PsppireDialogActionIndepSamps GtkWidget *options_button; /* The variable which determines to which group a datum belongs */ - const struct variable *grp_var; + struct variable *grp_var; int grp_var_width; /* The GtkEntry which holds the reference to the above variable */ diff --git a/src/ui/gui/psppire-var-ptr.c b/src/ui/gui/psppire-var-ptr.c index a2f65a3946..a5511ec31f 100644 --- a/src/ui/gui/psppire-var-ptr.c +++ b/src/ui/gui/psppire-var-ptr.c @@ -28,17 +28,17 @@ */ -/* Shallow copy the pointer */ static gpointer variable_copy (gpointer var) { - return var; + struct variable *v = var; + return var_ref (v); } -/* Do nothing. It's a pointer only! */ static void variable_free (gpointer var) { + var_unref (var); } -- 2.30.2