Fix memory leak in rank_sorted_casefile().
[pspp-builds.git] / src / language / stats / rank.q
index c102d195c08c3b09227f6fe6864c362f90fd4ea0..491160b6097a702eb51854b06e2cbdb6b42cd02d 100644 (file)
@@ -264,7 +264,8 @@ rank_cmd (const struct sort_criteria *sc,
 
       /* Obtain active file in CF. */
       if (!procedure (NULL, NULL))
-       return false;
+       goto error;
+
       cf = proc_capture_output ();
 
       /* Sort CF into SORTED_CF. */
@@ -285,9 +286,13 @@ rank_cmd (const struct sort_criteria *sc,
       
       proc_set_source (storage_source_create (out));
     }
-  free (criteria.crits);
 
+  free (criteria.crits);
   return result ; 
+
+error:
+  free (criteria.crits);
+  return false ;
 }
 
 /* Hardly a rank function !! */
@@ -621,11 +626,14 @@ rank_sorted_casefile (struct casefile *cf,
                          dest_idx, dest);
 
               w = 0.0;
+              case_destroy (&group_case);
               case_move (&group_case, &this_case);
             }
          if ( !value_is_missing (mv, this_value) )
            w += c;
+          case_destroy (&this_case);
         }
+      case_destroy (&group_case);
       rank_cases (pos, ULONG_MAX, ultimate_crit, mv, w,
                  rs, n_rank_specs, dest_idx, dest);
     }