LIST: Fix crash when SPLIT FILE was used.
[pspp-builds.git] / src / language / data-io / list.q
index 60f51b523b0c0250abbe4ae43753880be464ff4b..ddc072a46b5ebaad10b5ed03dc6d0136d5c824f3 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2006, 2009 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006, 2009-2011 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "intprops.h"
-#include "xmalloca.h"
-
-#include <data/casegrouper.h>
-#include <data/casereader.h>
-#include <data/dictionary.h>
-#include <data/data-out.h>
-#include <data/format.h>
-#include <data/procedure.h>
-#include <data/subcase.h>
-#include <data/variable.h>
-#include <language/command.h>
-#include <language/dictionary/split-file.h>
-#include <language/lexer/lexer.h>
-#include <libpspp/compiler.h>
-#include <libpspp/ll.h>
-#include <libpspp/message.h>
-#include <libpspp/misc.h>
-#include <output/tab.h>
-#include <output/table-item.h>
-
-#include "minmax.h"
-#include "xalloc.h"
+#include "data/casegrouper.h"
+#include "data/casereader.h"
+#include "data/dataset.h"
+#include "data/dictionary.h"
+#include "data/data-out.h"
+#include "data/format.h"
+#include "data/subcase.h"
+#include "data/variable.h"
+#include "language/command.h"
+#include "language/dictionary/split-file.h"
+#include "language/lexer/lexer.h"
+#include "libpspp/compiler.h"
+#include "libpspp/ll.h"
+#include "libpspp/message.h"
+#include "libpspp/misc.h"
+#include "output/tab.h"
+#include "output/table-item.h"
+
+#include "gl/intprops.h"
+#include "gl/minmax.h"
+#include "gl/xalloc.h"
+#include "gl/xmalloca.h"
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
@@ -131,13 +130,6 @@ cmd_list (struct lexer *lexer, struct dataset *ds)
       struct ccase *ccase;
       struct table *t;
 
-      group = casereader_project (group, &sc);
-      if (cmd.numbering == LST_NUMBERED)
-        group = casereader_create_arithmetic_sequence (group, 1, 1);
-      group = casereader_select (group, cmd.first - 1,
-                                 (cmd.last != LONG_MAX ? cmd.last
-                                  : CASENUMBER_MAX), cmd.step);
-
       ccase = casereader_peek (group, 0);
       if (ccase != NULL)
         {
@@ -145,6 +137,13 @@ cmd_list (struct lexer *lexer, struct dataset *ds)
           case_unref (ccase);
         }
 
+      group = casereader_project (group, &sc);
+      if (cmd.numbering == LST_NUMBERED)
+        group = casereader_create_arithmetic_sequence (group, 1, 1);
+      group = casereader_select (group, cmd.first - 1,
+                                 (cmd.last != LONG_MAX ? cmd.last
+                                  : CASENUMBER_MAX), cmd.step);
+
       if (cmd.numbering == LST_NUMBERED)
         {
           struct fmt_spec fmt;
@@ -178,6 +177,7 @@ cmd_list (struct lexer *lexer, struct dataset *ds)
   ok = proc_commit (ds) && ok;
 
   subcase_destroy (&sc);
+  free (cmd.v_variables);
 
   return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
 }