Simplify psppire-var-view and its relationship to psppire-means-layer
[pspp] / src / language / stats / logistic.c
index 9a9e4e91bfc385dc8acf5361c27a8cef25c2490d..eb200fe37889c54c04596068614167735faa13d1 100644 (file)
@@ -523,6 +523,7 @@ initial_pass (const struct lr_spec *cmd, struct lr_result *res, struct casereade
              )
            {
              msg (ME, _("Dependent variable's values are not dichotomous."));
+              case_unref (c);
              goto error;
            }
        }
@@ -594,11 +595,12 @@ run_lr (const struct lr_spec *cmd, struct casereader *input,
   work.warn_bad_weight = true;
   work.cats = NULL;
   work.beta_hat = NULL;
+  work.hessian = NULL;
 
   /* Get the initial estimates of \beta and their standard errors.
      And perform other auxilliary initialisation.  */
   if (! initial_pass (cmd, &work, input))
-    return false;
+    goto error;
   
   for (i = 0; i < cmd->n_cat_predictors; ++i)
     {
@@ -612,7 +614,7 @@ run_lr (const struct lr_spec *cmd, struct casereader *input,
          msg (ME, _("Category %s does not have at least two distinct values. Logistic regression will not be run."),
               ds_cstr(&str));
          ds_destroy (&str);
-         return false;
+         goto error;
        }
     }
 
@@ -692,7 +694,7 @@ run_lr (const struct lr_spec *cmd, struct casereader *input,
       if (converged)
        break;
     }
-  casereader_destroy (input);
+
 
 
   if ( ! converged) 
@@ -707,12 +709,20 @@ run_lr (const struct lr_spec *cmd, struct casereader *input,
   output_classification_table (cmd, &work);
   output_variables (cmd, &work);
 
+  casereader_destroy (input);
   gsl_matrix_free (work.hessian);
   gsl_vector_free (work.beta_hat); 
-  
   categoricals_destroy (work.cats);
 
   return true;
+
+ error:
+  casereader_destroy (input);
+  gsl_matrix_free (work.hessian);
+  gsl_vector_free (work.beta_hat); 
+  categoricals_destroy (work.cats);
+
+  return false;
 }
 
 struct variable_node