shapiro-wilk: Fix memory leak.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 21 Jul 2019 04:34:41 +0000 (21:34 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 21 Jul 2019 04:34:41 +0000 (21:34 -0700)
CC: John Darrington <john@darrington.wattle.id.au>
Fixes: 0b7e8882ce9b ("EXAMINE: Implement the Shapiro-Wilk Test.")
src/math/shapiro-wilk.c

index f48156e97cfdd5605e36f98e9b00ebaa90971b7c..30feb39d9ddfb94cb9f844ae5f78444657a54126 100644 (file)
@@ -116,6 +116,9 @@ shapiro_wilk_calculate (const struct shapiro_wilk *sw)
 struct shapiro_wilk *
 shapiro_wilk_create (int n, double mean)
 {
+  if (n < 3 || n > 5000)
+    return NULL;
+
   struct shapiro_wilk *sw = xzalloc (sizeof (*sw));
   struct order_stats *os = &sw->parent;
   struct statistic *stat = &os->parent;
@@ -128,9 +131,6 @@ shapiro_wilk_create (int n, double mean)
 
   sw->n = n;
 
-  if (n < 3 || n > 5000)
-    return NULL;
-
   const double u = 1.0 / sqrt (sw->n);
 
   double m = 0;