Fix memory leak in examine
[pspp] / src / language / stats / examine.q
index 41a43abfe9a362c5e2f57f1d91718a93c33a437f..d4ac27dde74044a92f48d3748df8e3e1ce0dd4ca 100644 (file)
 #include <libpspp/misc.h>
 #include <libpspp/str.h>
 #include <math/moments.h>
-#include <output/charts/box-whisker.h>
+#include <output/chart-item.h>
+#include <output/charts/boxplot.h>
 #include <output/charts/np-plot.h>
-#include <output/manager.h>
-#include <output/table.h>
+#include <output/tab.h>
 
 #include "minmax.h"
 #include "xalloc.h"
@@ -61,9 +61,7 @@
 #define N_(msgid) msgid
 
 /* (headers) */
-#include <output/chart.h>
 #include <output/charts/plot-hist.h>
-#include <output/charts/plot-chart.h>
 #include <math/histogram.h>
 
 /* (specification)
@@ -339,7 +337,7 @@ show_npplot (const struct variable **dependent_var,
          struct string label;
          const struct factor_result *result =
            ll_data (ll, struct factor_result, ll);
-          struct chart *npp, *dnpp;
+          struct chart_item *npp, *dnpp;
           struct casereader *reader;
           struct np *np;
 
@@ -357,16 +355,17 @@ show_npplot (const struct variable **dependent_var,
           if (npp == NULL || dnpp == NULL)
             {
               msg (MW, _("Not creating NP plot because data set is empty."));
-              chart_unref (npp);
-              chart_unref (dnpp);
+              chart_item_unref (npp);
+              chart_item_unref (dnpp);
             }
           else
             {
-              chart_submit (npp);
-              chart_submit (dnpp);
+              chart_item_submit (npp);
+              chart_item_submit (dnpp);
             }
 
          statistic_destroy (&np->parent.parent);
+         casereader_destroy (reader);
        }
     }
 }
@@ -406,8 +405,9 @@ show_histogram (const struct variable **dependent_var,
 
           moments1_calculate (result->metrics[v].moments,
                               &n, &mean, &var, NULL,  NULL);
-          chart_submit (histogram_chart_create (histogram, ds_cstr (&str),
-                                                n, mean, sqrt (var), false));
+          chart_item_submit (histogram_chart_create (histogram->gsl_hist,
+                                                     ds_cstr (&str), n, mean,
+                                                     sqrt (var), false));
 
          ds_destroy (&str);
        }
@@ -471,7 +471,7 @@ show_boxplot_groups (const struct variable **dependent_var,
          ds_destroy (&str);
        }
 
-      chart_submit (boxplot_get_chart (boxplot));
+      boxplot_submit (boxplot);
     }
 }
 
@@ -519,7 +519,7 @@ show_boxplot_variables (const struct variable **dependent_var,
           metrics->box_whisker = NULL;
        }
 
-      chart_submit (boxplot_get_chart (boxplot));
+      boxplot_submit (boxplot);
     }
 }
 
@@ -986,11 +986,12 @@ examine_group (struct cmd_examine *cmd, struct casereader *reader, int level,
          struct factor_metrics *metric = &result->metrics[v];
           int n_vals = caseproto_get_n_widths (casereader_get_proto (
                                                  metric->up_reader));
-          struct order_stats *os = &metric->box_whisker->parent;
+          struct order_stats *os;
 
          metric->box_whisker =
            box_whisker_create ( metric->tukey_hinges, cmd->v_id, n_vals - 1);
 
+          os = &metric->box_whisker->parent;
          order_stats_accumulate ( &os, 1,
                                  casereader_clone (metric->up_reader),
                                  wv, dependent_vars[v], MV_ANY);
@@ -1131,11 +1132,9 @@ show_summary (const struct variable **dependent_var, int n_dep_var,
 
   n_cols = heading_columns + 6;
 
-  tbl = tab_create (n_cols, n_rows, 0);
+  tbl = tab_create (n_cols, n_rows);
   tab_headers (tbl, heading_columns, 0, heading_rows, 0);
 
-  tab_dim (tbl, tab_natural_dimensions, NULL, NULL);
-
   /* Outline the box */
   tab_box (tbl,
           TAL_2, TAL_2,
@@ -1368,11 +1367,9 @@ show_descriptives (const struct variable **dependent_var,
 
   n_cols = heading_columns + 2;
 
-  tbl = tab_create (n_cols, n_rows, 0);
+  tbl = tab_create (n_cols, n_rows);
   tab_headers (tbl, heading_columns, 0, heading_rows, 0);
 
-  tab_dim (tbl, tab_natural_dimensions, NULL, NULL);
-
   /* Outline the box */
   tab_box (tbl,
           TAL_2, TAL_2,
@@ -1680,11 +1677,9 @@ show_extremes (const struct variable **dependent_var,
 
   n_cols = heading_columns + 2;
 
-  tbl = tab_create (n_cols, n_rows, 0);
+  tbl = tab_create (n_cols, n_rows);
   tab_headers (tbl, heading_columns, 0, heading_rows, 0);
 
-  tab_dim (tbl, tab_natural_dimensions, NULL, NULL);
-
   /* Outline the box */
   tab_box (tbl,
           TAL_2, TAL_2,
@@ -1775,7 +1770,6 @@ show_extremes (const struct variable **dependent_var,
              min_ll = ll_next (min_ll);
            }
 
-
          max_ll = ll_head (extrema_list (result->metrics[v].maxima));
          for (e = 0; e < cmd.st_n;)
            {
@@ -1885,11 +1879,9 @@ show_percentiles (const struct variable **dependent_var,
 
   n_cols = heading_columns + n_percentiles;
 
-  tbl = tab_create (n_cols, n_rows, 0);
+  tbl = tab_create (n_cols, n_rows);
   tab_headers (tbl, heading_columns, 0, heading_rows, 0);
 
-  tab_dim (tbl, tab_natural_dimensions, NULL, NULL);
-
   /* Outline the box */
   tab_box (tbl,
           TAL_2, TAL_2,