Fix numerous memory leaks.
[pspp] / src / output / charts / boxplot.c
index 7e9248004b3c2b2662f684241e55ab06b865b0c4..0abb971f44a28909cf7939c3b78b2dc57ede2937 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2004, 2008, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2008, 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 <config.h>
 
-#include <output/charts/boxplot.h>
+#include "output/charts/boxplot.h"
 
-#include <math/box-whisker.h>
-#include <output/chart-item-provider.h>
+#include "math/box-whisker.h"
+#include "output/chart-item-provider.h"
 
 struct boxplot *
 boxplot_create (double y_min, double y_max, const char *title)
 {
+  if (y_min >= y_max)
+    return NULL;
   struct boxplot *boxplot = xmalloc (sizeof *boxplot);
   chart_item_init (&boxplot->chart_item, &boxplot_class, title);
   boxplot->y_min = y_min;
@@ -38,6 +40,13 @@ void
 boxplot_add_box (struct boxplot *boxplot,
                  struct box_whisker *bw, const char *label)
 {
+  if (boxplot == NULL)
+    {
+      struct statistic *statistic = &bw->parent.parent;
+      statistic->destroy (statistic);
+      return;
+    }
+
   struct boxplot_box *box;
   if (boxplot->n_boxes >= boxplot->boxes_allocated)
     boxplot->boxes = x2nrealloc (boxplot->boxes, &boxplot->boxes_allocated,
@@ -51,6 +60,9 @@ static void
 boxplot_chart_destroy (struct chart_item *chart_item)
 {
   struct boxplot *boxplot = to_boxplot (chart_item);
+  if (boxplot == NULL)
+    return;
+
   size_t i;
 
   for (i = 0; i < boxplot->n_boxes; i++)