Fix memory leak in barcharts
authorJohn Darrington <john@darrington.wattle.id.au>
Mon, 1 Feb 2016 11:18:10 +0000 (12:18 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Mon, 1 Feb 2016 11:18:10 +0000 (12:18 +0100)
src/output/charts/barchart.c
src/output/charts/barchart.h

index 07a39e818f65193b6ddc6ed4816eab19c3a65dd5..812a96d03a5b5cec1ca273585acf26fd799136b5 100644 (file)
@@ -136,8 +136,9 @@ barchart_create (const struct variable **var, int n_vars,
            {
              struct category *s = xzalloc (sizeof *s);
              s->idx = idx++;
-             value_init (&s->val, var_get_width (var[pidx]));
-             value_copy (&s->val, &src->values[pidx], var_get_width (var[pidx]));
+             s->width = var_get_width (var[pidx]);
+             value_init (&s->val, s->width);
+             value_copy (&s->val, &src->values[pidx], s->width);
              ds_init_empty (&s->label);
              var_append_value_name (var[pidx], &s->val, &s->label);
 
@@ -173,7 +174,8 @@ barchart_create (const struct variable **var, int n_vars,
            {
              struct category *s = xzalloc (sizeof *s);
              s->idx = idx++;
-             value_init (&s->val, var_get_width (var[sidx]));
+             s->width = var_get_width (var[sidx]);
+             value_init (&s->val, s->width);
              value_copy (&s->val, &src->values[sidx], var_get_width (var[sidx]));
              ds_init_empty (&s->label);
              var_append_value_name (var[sidx], &s->val, &s->label);
@@ -256,6 +258,8 @@ destroy_cat_map (struct hmap *m)
   struct category *next = NULL;
   HMAP_FOR_EACH_SAFE (foo, next, struct category, node, m)
     {
+      value_destroy (&foo->val, foo->width);
+
       ds_destroy (&foo->label);
       free (foo);
     }
index dabf61b05036861d84b6307ab4fec151a3833ef6..d47ce165bb24d641f67ced9f2dcf9ea0e260f903 100644 (file)
@@ -29,6 +29,7 @@ struct category
   int idx;                     /* Unique zero based index */
   struct string label;         /* The label to be displayed for this category */
   union value val;             /* The value of this category */
+  int width;                   /* The width of VAL */
 };