leaks
authorBen Pfaff <blp@cs.stanford.edu>
Thu, 4 Aug 2022 17:03:44 +0000 (10:03 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Thu, 4 Aug 2022 17:03:44 +0000 (10:03 -0700)
src/language/stats/ctables.c

index dd97afc0cc97e3c56adffc9a643ae60a8e831406..e54be6d64bcfcb9d602438285945e8a41dad455e 100644 (file)
@@ -835,7 +835,8 @@ static void
 ctables_summary_spec_set_clone (struct ctables_summary_spec_set *dst,
                                 const struct ctables_summary_spec_set *src)
 {
-  struct ctables_summary_spec *specs = xnmalloc (src->n, sizeof *specs);
+  struct ctables_summary_spec *specs
+    = (src->n ? xnmalloc (src->n, sizeof *specs) : NULL);
   for (size_t i = 0; i < src->n; i++)
     ctables_summary_spec_clone (&specs[i], &src->specs[i]);
 
@@ -1554,6 +1555,7 @@ ctables_table_destroy (struct ctables_table *t)
       ctables_axis_destroy (t->axes[a]);
       ctables_stack_uninit (&t->stacks[a]);
     }
+  free (t->summary_specs.specs);
 
   struct ctables_value *ctv, *next_ctv;
   HMAP_FOR_EACH_SAFE (ctv, next_ctv, struct ctables_value, node,
@@ -1581,6 +1583,23 @@ ctables_destroy (struct ctables *ct)
   if (!ct)
     return;
 
+  struct ctables_postcompute *pc, *next_pc;
+  HMAP_FOR_EACH_SAFE (pc, next_pc, struct ctables_postcompute, hmap_node,
+                      &ct->postcomputes)
+    {
+      free (pc->name);
+      msg_location_destroy (pc->location);
+      ctables_pcexpr_destroy (pc->expr);
+      free (pc->label);
+      if (pc->specs)
+        {
+          ctables_summary_spec_set_uninit (pc->specs);
+          free (pc->specs);
+        }
+      hmap_delete (&ct->postcomputes, &pc->hmap_node);
+      free (pc);
+    }
+
   fmt_settings_uninit (&ct->ctables_formats);
   pivot_table_look_unref (ct->look);
   free (ct->zero);
@@ -2352,8 +2371,9 @@ error:
 static void
 ctables_nest_uninit (struct ctables_nest *nest)
 {
-  if (nest)
-    free (nest->vars);
+  free (nest->vars);
+  for (enum ctables_summary_variant sv = 0; sv < N_CSVS; sv++)
+    ctables_summary_spec_set_uninit (&nest->specs[sv]);
 }
 
 static void
@@ -5069,6 +5089,7 @@ ctables_prepare_table (struct ctables_table *t)
           j++;
         }
     }
+  free (items);
 
 #if 0
   for (size_t j = 0; j < merged->n; j++)
@@ -5376,9 +5397,15 @@ ctables_section_uninit (struct ctables_section *s)
 
   for (enum pivot_axis_type a = 0; a < PIVOT_N_AXES; a++)
     {
-      for (size_t i = 0; i < s->nests[a]->n; i++)
+      struct ctables_nest *nest = s->nests[a];
+      for (size_t i = 0; i < nest->n; i++)
         hmap_destroy (&s->occurrences[a][i]);
       free (s->occurrences[a]);
+      for (enum ctables_domain_type dt = 0; dt < N_CTDTS; dt++)
+        {
+          free (nest->domains[dt]);
+          nest->domains[dt] = NULL;
+        }
     }
 
   hmap_destroy (&s->cells);