[gnumeric] solver: leak fixed and FMR avoidance.



commit 35b9fd2b1f812cfa92cb8c127f1d1d3a96ddfc5e
Author: Morten Welinder <terra gnome org>
Date:   Thu Nov 5 12:32:10 2009 -0500

    solver: leak fixed and FMR avoidance.

 plugins/mps/mps.c           |   25 ++++++++++++-------------
 plugins/mps/parser.c        |    6 ++++--
 src/dialogs/dialog-solver.c |    6 ++++--
 src/tools/solver/solver.c   |   10 ++--------
 4 files changed, 22 insertions(+), 25 deletions(-)
---
diff --git a/plugins/mps/mps.c b/plugins/mps/mps.c
index 68f8ba8..0956e06 100644
--- a/plugins/mps/mps.c
+++ b/plugins/mps/mps.c
@@ -566,36 +566,35 @@ mps_input_context_destroy (MpsInputContext *ctxt)
 
 	/* Free ROWS */
 	for (current = ctxt->rows; current != NULL; current = current->next) {
-	           MpsRow *row = (MpsRow *) current->data;
+	           MpsRow *row = current->data;
 		   g_free (row->name);
-		   g_free (current->data);
+		   g_free (row);
 	}
+	g_slist_free (ctxt->rows);
 
 	/* Free COLUMNS */
 	for (current = ctxt->cols; current != NULL; current = current->next) {
-	           MpsCol *col = (MpsCol *) current->data;
+	           MpsCol *col = current->data;
 		   g_free (col->name);
-		   g_free (current->data);
+		   g_free (col);
 	}
-
+	g_slist_free (ctxt->cols);
 	ctxt->cols = NULL;
+
 	/* Free RHSs */
 	for (current = ctxt->rhs; current != NULL; current = current->next) {
-	           MpsRhs *rhs = (MpsRhs *) current->data;
+	           MpsRhs *rhs = current->data;
 		   g_free (rhs->name);
-		   g_free (current->data);
+		   g_free (rhs);
 	}
+	g_slist_free (ctxt->rhs);
 
 	/* Free BOUNDS */
 	for (current = ctxt->bounds; current!=NULL; current = current->next) {
-	           MpsBound *bound = (MpsBound *) current->data;
+	           MpsBound *bound = current->data;
 		   g_free (bound->name);
-		   g_free (current->data);
+		   g_free (bound);
 	}
-
-	g_slist_free (ctxt->rows);
-	g_slist_free (ctxt->cols);
-	g_slist_free (ctxt->rhs);
 	g_slist_free (ctxt->bounds);
 
 	g_hash_table_foreach_remove (ctxt->row_hash, (GHRFunc) rh_rm_cb, NULL);
diff --git a/plugins/mps/parser.c b/plugins/mps/parser.c
index ab9a590..00ad414 100644
--- a/plugins/mps/parser.c
+++ b/plugins/mps/parser.c
@@ -226,8 +226,10 @@ mps_add_row (MpsInputContext *ctxt, MpsRowType type, gchar *txt)
 	row = g_new (MpsRow, 1);
 	len = strlen(txt);
 
-	if (len == 0)
-	          return FALSE;
+	if (len == 0) {
+		g_free (row);
+		return FALSE;
+	}
 
 	row->name = g_strdup (txt);
 	row->type = type;
diff --git a/src/dialogs/dialog-solver.c b/src/dialogs/dialog-solver.c
index ed5a995..4a179b2 100644
--- a/src/dialogs/dialog-solver.c
+++ b/src/dialogs/dialog-solver.c
@@ -502,7 +502,7 @@ cb_dialog_solve_clicked (G_GNUC_UNUSED GtkWidget *button,
 	GError *err = NULL;
 	SolverParameters        *param;
 	GtkTreeIter iter;
-	gchar const *name;
+	gchar *name;
 	GnmCell *target_cell;
 
 	param = state->sheet->solver_parameters;
@@ -529,7 +529,8 @@ cb_dialog_solve_clicked (G_GNUC_UNUSED GtkWidget *button,
 		gnumeric_glade_group_value (state->gui, model_type_group);
 
 	gtk_combo_box_get_active_iter (state->algorithm_combo, &iter);
-	gtk_tree_model_get (gtk_combo_box_get_model (state->algorithm_combo), &iter, 0, &name, -1);
+	gtk_tree_model_get (gtk_combo_box_get_model (state->algorithm_combo),
+			    &iter, 0, &name, -1);
 	for (i = 0; algorithm_defs[i].name; i++) {
 		if (param->options.model_type == algorithm_defs[i].type)
 			if (strcmp (algorithm_defs[i].name, name) == 0) {
@@ -538,6 +539,7 @@ cb_dialog_solve_clicked (G_GNUC_UNUSED GtkWidget *button,
 				break;
 			}
 	}
+	g_free (name);
 
 	param->options.assume_non_negative = gtk_toggle_button_get_active
 		(GTK_TOGGLE_BUTTON (glade_xml_get_widget (state->gui,
diff --git a/src/tools/solver/solver.c b/src/tools/solver/solver.c
index 6d30b63..85c859e 100644
--- a/src/tools/solver/solver.c
+++ b/src/tools/solver/solver.c
@@ -426,6 +426,8 @@ solver_results_free (SolverResults *res)
 	g_free (res->slack);
 	g_free (res->lhs);
 	g_free (res->rhs);
+
+	memset (res, 0xff, sizeof (*res));
 	g_free (res);
 }
 
@@ -916,7 +918,6 @@ lp_qp_solver_init (Sheet *sheet, const SolverParameters *param,
 				     _("The LHS cells should contain formulas "
 				       "that yield proper numerical values.  "
 				       "Specify valid LHS entries."));
-			solver_results_free (res);
 			return NULL;
 		}
 		lx = value_get_as_float (lval);
@@ -962,7 +963,6 @@ lp_qp_solver_init (Sheet *sheet, const SolverParameters *param,
 				     _("The RHS cells should contain proper "
 				       "numerical values only.  Specify valid "
 				       "RHS entries."));
-			solver_results_free (res);
 			return NULL;
 		}
 		rx = value_get_as_float (rval);
@@ -978,7 +978,6 @@ lp_qp_solver_init (Sheet *sheet, const SolverParameters *param,
 		    param->options.max_time_sec) {
 			g_set_error (err, go_error_invalid (), 0,
 				     SOLVER_MAX_TIME_ERR);
-			solver_results_free (res);
 			return NULL;
 		}
 
@@ -996,11 +995,9 @@ lp_qp_solver_init (Sheet *sheet, const SolverParameters *param,
 		g_set_error (err, go_error_invalid (), 0,
 			     _("EqualTo models are not supported yet.  "
 			       "Please use Min or Max"));
-		solver_results_free (res);
 	        return NULL; /* FIXME: Equal to feature not yet implemented. */
 	default:
 		g_warning ("unknown problem type %d", param->problem_type);
-		solver_results_free (res);
 	        return NULL;
 	}
 
@@ -1010,21 +1007,18 @@ lp_qp_solver_init (Sheet *sheet, const SolverParameters *param,
 				NULL, NULL)) {
 		g_set_error (err, go_error_invalid (), 0,
 			     _("Failure setting automatic scaling with this solver, try a different algorithm."));
-		solver_results_free (res);
 	        return NULL;
 	}
 	if (alg->set_option_fn (program, SolverOptMaxIter, NULL, NULL,
 				&(param->options.max_iter))) {
 		g_set_error (err, go_error_invalid (), 0,
 			     _("Failure setting the maximum number of iterations with this solver, try a different algorithm."));
-		solver_results_free (res);
 	        return NULL;
 	}
 	if (alg->set_option_fn (program, SolverOptMaxTimeSec, NULL, &start_time,
 				&(param->options.max_time_sec))) {
 		g_set_error (err, go_error_invalid (), 0,
 			     _("Failure setting the maximum solving time with this solver, try a different algorithm."));
-		solver_results_free (res);
 	        return NULL;
 	}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]