Fix memory leaks in ONEWAY command
authorJohn Darrington <john@darrington.wattle.id.au>
Sun, 12 Aug 2012 11:33:09 +0000 (13:33 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sun, 12 Aug 2012 11:33:09 +0000 (13:33 +0200)
src/language/stats/examine.c
src/language/stats/means.c
src/language/stats/oneway.c
src/math/categoricals.c
src/math/categoricals.h

index 4e4790eb3293382dc8acad7bef1ec772c1961f19..46b27f9d360ac34b1161a69de910aadb18eaba43 100644 (file)
@@ -1804,6 +1804,7 @@ run_examine (struct examine *cmd, struct casereader *input)
   payload.create = create_n;
   payload.update = update_n;
   payload.calculate = calculate_n;
+  payload.destroy = NULL;
   
   cmd->wv = dict_get_weight (cmd->dict);
 
index fec20877399aea3a12d20a9761714bea53a3d131..c67d75002f75c28716f9b52528d81fe344a4dd29 100644 (file)
@@ -1,3 +1,4 @@
+
 /* PSPP - a program for statistical analysis.
    Copyright (C) 2011, 2012 Free Software Foundation, Inc.
 
@@ -939,6 +940,7 @@ run_means (struct means *cmd, struct casereader *input,
   payload.create = create_n;
   payload.update = update_n;
   payload.calculate = calculate_n;
+  payload.destroy = NULL;
   
   for (t = 0; t < cmd->n_tables; ++t)
   {
index 08449103c522f92e834ffda095404780729614b4..2a412a3d7e7cc14e133bbdea4970666062943e44 100644 (file)
@@ -628,6 +628,15 @@ makeit (const void *aux1, void *aux2 UNUSED)
   return dd;
 }
 
+static void 
+killit (const void *aux1 UNUSED, void *user_data)
+{
+  struct descriptive_data *dd = user_data;
+
+  dd_destroy (dd);
+}
+
+
 static void 
 updateit (const void *aux1, void *aux2, void *user_data,
          const struct ccase *c, double weight)
@@ -691,6 +700,7 @@ run_oneway (const struct oneway_spec *cmd,
       payload.create = makeit;
       payload.update = updateit;
       payload.calculate = NULL;
+      payload.destroy = killit;
 
       ws.vws[v].cat = categoricals_create (&inter, 1, cmd->wv,
                                            cmd->exclude, cmd->exclude);
index 7eaf82195badf8dab7e63914cff3934cd6e3d68c..43edd048dc5324a8306133453096a0d079625708 100644 (file)
@@ -253,10 +253,8 @@ categoricals_destroy (struct categoricals *cat)
       /* Interate over each interaction value, and unref any cases that we reffed */
       HMAP_FOR_EACH (iv, struct interaction_value, node, &cat->iap[i].ivmap)
        {
-#if 0
-         if (cat->payload)
+         if (cat->payload && cat->payload->destroy)
            cat->payload->destroy (cat->aux1, iv->user_data);
-#endif
          case_unref (iv->ccase);
        }
 
index 11d64d02296d1ff58952ef33aa7cea3ccc76befe..3fa6c36d906a3d337a54e33de5a6806608007acb 100644 (file)
@@ -107,6 +107,7 @@ struct payload
   void* (*create)  (const void *aux1, void *aux2);
   void (*update)  (const void *aux1, void *aux2, void *user_data, const struct ccase *, double weight);
   void (*calculate) (const void *aux1, void *aux2, void *user_data);
+  void (*destroy) (const void *aux1, void *user_data);
 };