From 34bf67fbfdce409a1cefdc101518c633636c1f43 Mon Sep 17 00:00:00 2001 From: Jason H Stover Date: Fri, 22 Jan 2010 16:48:04 -0500 Subject: [PATCH] Set categoricals to NULL in one-pass covariance; avoid freeing NULL in categoricals_destroy --- src/math/categoricals.c | 13 ++++++++----- src/math/covariance.c | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/math/categoricals.c b/src/math/categoricals.c index 6002d8c1..33e3b51c 100644 --- a/src/math/categoricals.c +++ b/src/math/categoricals.c @@ -91,11 +91,14 @@ void categoricals_destroy ( struct categoricals *cat) { int i; - for (i = 0 ; i < cat->n_vp; ++i) - hmap_destroy (&cat->vp[i].map); - - pool_destroy (cat->pool); - free (cat); + if (cat != NULL) + { + for (i = 0 ; i < cat->n_vp; ++i) + hmap_destroy (&cat->vp[i].map); + + pool_destroy (cat->pool); + free (cat); + } } diff --git a/src/math/covariance.c b/src/math/covariance.c index d60d609e..1b5a2385 100644 --- a/src/math/covariance.c +++ b/src/math/covariance.c @@ -157,6 +157,7 @@ covariance_1pass_create (size_t n_vars, const struct variable **vars, cov->n_cm = (n_vars * (n_vars - 1) ) / 2; cov->cm = xcalloc (sizeof *cov->cm, cov->n_cm); + cov->categoricals = NULL; return cov; } -- 2.30.2