From 96c27d81b9e1161537ce3591c25cb38ae9b6698e Mon Sep 17 00:00:00 2001 From: John Darrington Date: Thu, 7 Jul 2011 12:14:29 +0200 Subject: [PATCH] GLM: Fix memory leaks --- src/language/stats/glm.c | 10 +++++++++- src/math/categoricals.c | 12 +++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/language/stats/glm.c b/src/language/stats/glm.c index 4ba93150..ba978c0a 100644 --- a/src/language/stats/glm.c +++ b/src/language/stats/glm.c @@ -63,7 +63,7 @@ struct glm_spec const struct variable **design_vars; size_t n_interactions; - const struct interaction **interactions; + struct interaction **interactions; enum mv_class exclude; @@ -104,6 +104,7 @@ static bool parse_design_spec (struct lexer *lexer, struct glm_spec *glm); int cmd_glm (struct lexer *lexer, struct dataset *ds) { + int i; struct const_var_set *factors = NULL; struct glm_spec glm; bool design = false; @@ -293,8 +294,11 @@ cmd_glm (struct lexer *lexer, struct dataset *ds) const_var_set_destroy (factors); free (glm.factor_vars); + for (i = 0 ; i < glm.n_interactions; ++i) + interaction_destroy (glm.interactions[i]); free (glm.interactions); free (glm.dep_vars); + free (glm.design_vars); return CMD_SUCCESS; @@ -303,8 +307,12 @@ error: const_var_set_destroy (factors); free (glm.factor_vars); + for (i = 0 ; i < glm.n_interactions; ++i) + interaction_destroy (glm.interactions[i]); + free (glm.interactions); free (glm.dep_vars); + free (glm.design_vars); return CMD_FAILURE; } diff --git a/src/math/categoricals.c b/src/math/categoricals.c index 58015c90..a3078d36 100644 --- a/src/math/categoricals.c +++ b/src/math/categoricals.c @@ -125,7 +125,17 @@ categoricals_destroy ( struct categoricals *cat) if (cat != NULL) { for (i = 0 ; i < cat->n_vp; ++i) - hmap_destroy (&cat->vp[i].map); + { + struct hmap *map = &cat->vp[i].map; + struct value_node *nn; + + HMAP_FOR_EACH (nn, struct value_node, node, map) + { + case_unref (nn->ccase); + } + + hmap_destroy (map); + } pool_destroy (cat->pool); free (cat); -- 2.30.2