work on memory leaks
authorBen Pfaff <blp@cs.stanford.edu>
Thu, 4 Aug 2022 06:13:03 +0000 (23:13 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Thu, 4 Aug 2022 06:13:03 +0000 (23:13 -0700)
src/language/stats/ctables.c

index 6fcd0c7d35e2a86c3f991773f8b21981842efa54..4b4d58d8a9add8c1e79a41b909c28449ad8b67ba 100644 (file)
@@ -445,6 +445,8 @@ struct ctables_stack
     size_t n;
   };
 
+static void ctables_stack_uninit (struct ctables_stack *);
+
 struct ctables_value
   {
     struct hmap_node node;
@@ -470,6 +472,8 @@ struct ctables_section
     struct hmap domains[N_CTDTS]; /* Contains "struct ctables_domain"s. */
   };
 
+static void ctables_section_uninit (struct ctables_section *);
+
 struct ctables_table
   {
     struct ctables *ctables;
@@ -1536,13 +1540,20 @@ ctables_table_destroy (struct ctables_table *t)
   if (!t)
     return;
 
+  for (size_t i = 0; i < t->n_sections; i++)
+    ctables_section_uninit (&t->sections[i]);
+  free (t->sections);
+
   for (size_t i = 0; i < t->n_categories; i++)
     ctables_categories_unref (t->categories[i]);
   free (t->categories);
 
-  ctables_axis_destroy (t->axes[PIVOT_AXIS_COLUMN]);
-  ctables_axis_destroy (t->axes[PIVOT_AXIS_ROW]);
-  ctables_axis_destroy (t->axes[PIVOT_AXIS_LAYER]);
+  for (enum pivot_axis_type a = 0; a < PIVOT_N_AXES; a++)
+    {
+      ctables_axis_destroy (t->axes[a]);
+      ctables_stack_uninit (&t->stacks[a]);
+    }
+
   free (t->caption);
   free (t->corner);
   free (t->title);
@@ -1557,6 +1568,7 @@ ctables_destroy (struct ctables *ct)
   if (!ct)
     return;
 
+  fmt_settings_uninit (&ct->ctables_formats);
   pivot_table_look_unref (ct->look);
   free (ct->zero);
   free (ct->missing);
@@ -4652,6 +4664,8 @@ ctables_table_output (struct ctables *ct, struct ctables_table *t)
             }
           free (sorted);
           free (groups);
+          free (levels);
+          free (sections);
         }
     }
 
@@ -5335,6 +5349,23 @@ ctables_section_clear (struct ctables_section *s)
     }
 }
 
+static void
+ctables_section_uninit (struct ctables_section *s)
+{
+  ctables_section_clear (s);
+
+  for (enum pivot_axis_type a = 0; a < PIVOT_N_AXES; a++)
+    {
+      for (size_t i = 0; i < s->nests[a]->n; i++)
+        hmap_destroy (&s->occurrences[a][i]);
+      free (s->occurrences[a]);
+    }
+
+  hmap_destroy (&s->cells);
+  for (size_t i = 0; i < N_CTDTS; i++)
+    hmap_destroy (&s->domains[i]);
+}
+
 static void
 ctables_table_clear (struct ctables_table *t)
 {