From c0b9ef120f69daabda403a823296b0ed352964e9 Mon Sep 17 00:00:00 2001
From: Ben Pfaff <blp@cs.stanford.edu>
Date: Thu, 16 Feb 2023 16:17:42 -0800
Subject: [PATCH] AGGREGATE: Fix crash with temporary transformations.

Thanks to Frans Houweling for reporting this bug at
https://lists.gnu.org/archive/html/bug-gnu-pspp/2023-01/msg00004.html
---
 src/language/commands/aggregate.c    |  2 +-
 tests/language/commands/aggregate.at | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/language/commands/aggregate.c b/src/language/commands/aggregate.c
index fac71b139e..24b22722a7 100644
--- a/src/language/commands/aggregate.c
+++ b/src/language/commands/aggregate.c
@@ -278,7 +278,7 @@ cmd_aggregate (struct lexer *lexer, struct dataset *ds)
     {
       /* The active dataset will be replaced by the aggregated data,
          so TEMPORARY is moot. */
-      proc_cancel_temporary_transformations (ds);
+      proc_make_temporary_transformations_permanent (ds);
       proc_discard_output (ds);
       output = autopaging_writer_create (dict_get_proto (agr.dict));
     }
diff --git a/tests/language/commands/aggregate.at b/tests/language/commands/aggregate.at
index a76870289b..ac3ad929aa 100644
--- a/tests/language/commands/aggregate.at
+++ b/tests/language/commands/aggregate.at
@@ -511,3 +511,21 @@ aggregate.sps:16: error: AGGREGATE: Number of source variables (1) does not matc
       | ^~~~~~~~~"
 ])
 AT_CLEANUP
+
+AT_SETUP([AGGREGATE - temporary transformations])
+AT_DATA([aggregate.sps], [dnl
+DATA LIST FREE /quakes (F2.0).
+BEGIN DATA
+1 2 3 4 5 6 7 8 9 10
+END DATA.
+TEMPORARY.
+SELECT IF quakes GT 5.
+AGGREGATE OUTFILE = *  /nrecs=NU.
+LIST.
+])
+AT_CHECK([pspp -O format=csv aggregate.sps], [0], [dnl
+Table: Data List
+nrecs
+5
+])
+AT_CLEANUP
-- 
2.30.2