Fix crash in gui, when T-TEST or ONEWAY while a filter is set.
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 13 Apr 2019 18:55:19 +0000 (20:55 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 13 Apr 2019 19:19:33 +0000 (21:19 +0200)
Fixes bug #54784

NEWS
src/data/dictionary.c

diff --git a/NEWS b/NEWS
index 3f61612fdb5e7f6c67a4fdabed3b2248b7f8d6fb..e535638d3646991b4aed406ebd018bf56b6c032d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,9 @@ Changes from 1.2.0 to 1.3.0:
  * The REGRESSION command now supports the /STATISTICS=COLLIN which
    outputs collinearity metrics for the data.
 
+ * A bug where the GUI would crash when T-TEST was executed whilst
+   a filter was set has been fixed.
+
 Changes from 1.0.1 to 1.2.0:
 
  * New experimental command SAVE DATA COLLECTION to save MDD files.
index 2a5f4d83e78846f8b9e5371515a68bdda875750d..427cae3669eb695ef282650965ebb5df0ca4cb23 100644 (file)
@@ -1114,6 +1114,22 @@ dict_set_filter (struct dictionary *d, struct variable *v)
   assert (v == NULL || dict_contains_var (d, v));
   assert (v == NULL || var_is_numeric (v));
 
+  /* When a filter is set, we ref the dictionary.
+     This is because the GUI maintains a pointer
+     to the dict's variables, and the variables'
+     addresses change in the callback.  */
+  if (d->filter == NULL && v != NULL)
+    {
+      d = dict_ref (d);
+    }
+
+  /* Deref the dict when a filter is removed.  */
+  if (d->filter != NULL && v == NULL)
+    {
+      assert (d->ref_cnt > 0);
+      dict_unref (d);
+    }
+
   d->filter = v;
 
   if (d->changed) d->changed (d, d->changed_data);