Fix memory leak
authorJohn Darrington <john@darrington.wattle.id.au>
Sun, 24 Jul 2011 09:11:20 +0000 (11:11 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Tue, 26 Jul 2011 10:36:39 +0000 (12:36 +0200)
src/math/categoricals.c

index 67ca1e9addc278f2bda5d0ee50a8a957ccfdfa9c..f1bd09023758c0777507ca752b7b8462c23d5ea1 100644 (file)
@@ -243,6 +243,29 @@ categoricals_dump (const struct categoricals *cat)
 void
 categoricals_destroy (struct categoricals *cat)
 {
+  struct variable_node *vn = NULL;
+  int i;
+  for (i = 0; i < cat->n_iap; ++i)
+    {
+      struct interaction_value *iv = NULL;
+      /* Interate over each interaction value, and unref any cases that we reffed */
+      HMAP_FOR_EACH (iv, struct interaction_value, node, &cat->iap[i].ivmap)
+       {
+         case_unref (iv->ccase);
+       }
+      hmap_destroy (&cat->iap[i].ivmap);
+    }
+
+  /* Interate over each variable and delete its value map */
+  HMAP_FOR_EACH (vn, struct variable_node, node, &cat->varmap)
+    {
+      hmap_destroy (&vn->valmap);
+    }
+
+  hmap_destroy (&cat->varmap);
+
+  pool_destroy (cat->pool);
+
   free (cat);
 }