pivot-table: Fix memory leaks in pivot_table_dump().
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 19 Oct 2019 05:46:03 +0000 (05:46 +0000)
committerBen Pfaff <blp@cs.stanford.edu>
Wed, 30 Oct 2019 22:41:21 +0000 (22:41 +0000)
# Conflicts:
# src/output/pivot-table.c

src/output/pivot-table.c

index 4908697df4f28f0b1ed280e2cc5d2903f18e5aa1..ba3d98c916ad3f798d8980f5a8562cee9e269f70 100644 (file)
@@ -1352,6 +1352,18 @@ compose_headings (const struct pivot_axis *axis,
   return headings;
 }
 
+static void
+free_headings (const struct pivot_axis *axis, char ***headings)
+{
+  for (size_t i = 0; i < axis->label_depth; i++)
+    {
+      for (size_t j = 0; j < axis->extent; j++)
+        free (headings[i][j]);
+      free (headings[i]);
+    }
+  free (headings);
+}
+
 void
 pivot_table_dump (const struct pivot_table *table, int indentation)
 {
@@ -1470,6 +1482,7 @@ pivot_table_dump (const struct pivot_table *table, int indentation)
             }
           putchar ('\n');
         }
+      free_headings (&table->axes[PIVOT_AXIS_COLUMN], column_headings);
 
       indent (indentation + 1);
       printf ("-----------------------------------------------\n");
@@ -1518,6 +1531,7 @@ pivot_table_dump (const struct pivot_table *table, int indentation)
 
       free (column_enumeration);
       free (row_enumeration);
+      free_headings (&table->axes[PIVOT_AXIS_ROW], row_headings);
     }
 
   pivot_table_dump_value (table->caption, "caption", indentation);
@@ -1536,6 +1550,7 @@ pivot_table_dump (const struct pivot_table *table, int indentation)
       putchar ('\n');
     }
 
+  free (dindexes);
   settings_set_decimal_char (old_decimal);
 }
 \f