table: Fix memory leak.
[pspp] / src / output / table.c
index 2a08e14b5558cd50cc95386b6d2339720ce8c7bb..e354bb3edfc540a9b920a61e68a3e59fe773d411 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2009, 2011, 2014 Free Software Foundation, Inc.
+   Copyright (C) 2009, 2011, 2014, 2016 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -24,6 +24,7 @@
 
 #include "libpspp/cast.h"
 #include "libpspp/compiler.h"
+#include "output/table-item.h"
 
 #include "gl/xalloc.h"
 
@@ -320,6 +321,7 @@ table_string_get_cell (const struct table *ts_, int x UNUSED, int y UNUSED,
   cell->inline_contents.options = ts->options;
   cell->inline_contents.text = ts->string;
   cell->inline_contents.table = NULL;
+  cell->inline_contents.n_footnotes = 0;
   cell->n_contents = 1;
   cell->destructor = NULL;
 }
@@ -344,19 +346,28 @@ static const struct table_class table_string_class =
 struct table_nested
   {
     struct table table;
-    struct table *inner;
+    struct table_item *inner;
   };
 
 static const struct table_class table_nested_class;
 
-/* Creates and returns a table with a single cell that contains INNER. */
+/* Creates and returns a table with a single cell that contains INNER.
+   Takes ownership of INNER. */
 struct table *
-table_create_nested (const struct table *inner)
+table_create_nested (struct table *inner)
+{
+  return table_create_nested_item (table_item_create (inner, NULL, NULL));
+}
+
+/* Creates and returns a table with a single cell that contains INNER.
+   Takes ownership of INNER. */
+struct table *
+table_create_nested_item (struct table_item *inner)
 {
   struct table_nested *tn = xmalloc (sizeof *tn);
   table_init (&tn->table, &table_nested_class);
   tn->table.n[TABLE_HORZ] = tn->table.n[TABLE_VERT] = 1;
-  tn->inner = table_ref (inner);
+  tn->inner = inner;
   return &tn->table;
 }
 
@@ -371,7 +382,7 @@ static void
 table_nested_destroy (struct table *tn_)
 {
   struct table_nested *tn = table_nested_cast (tn_);
-  table_unref (tn->inner);
+  table_item_unref (tn->inner);
   free (tn);
 }
 
@@ -388,6 +399,7 @@ table_nested_get_cell (const struct table *tn_, int x UNUSED, int y UNUSED,
   cell->inline_contents.options = TAB_LEFT;
   cell->inline_contents.text = NULL;
   cell->inline_contents.table = tn->inner;
+  cell->inline_contents.n_footnotes = 0;
   cell->n_contents = 1;
   cell->destructor = NULL;
 }