Fix bug #54784 (again).
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 27 Jun 2020 16:00:16 +0000 (18:00 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 27 Jun 2020 16:00:16 +0000 (18:00 +0200)
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
src/ui/gui/psppire-dialog-action-indep-samps.h
src/ui/gui/psppire-var-ptr.c

index faea2b41414975e1bf0519c4614e3de0bdb7fcd9..f0995e92e85befe5918b06db37371519a08812d7 100644 (file)
@@ -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;
 }
 
index 672a40307448f3e0fdcb1abd9a65c157c40d73f5..e6ae0aaef02598959a52176a06561137b3f3b211 100644 (file)
@@ -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 */
index a2f65a3946280b02fc83c2a00e6f71f7a7715477..a5511ec31fc0f7848374a1ca59a1a6e376859801 100644 (file)
 */
 
 
-/* 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);
 }