[gnumeric] scenarios: plug leaks.



commit 0507724a23c53a28c13dc55fff25ff0fe038ef1b
Author: Morten Welinder <terra gnome org>
Date:   Thu Nov 26 00:04:02 2009 -0500

    scenarios: plug leaks.

 src/dialogs/dialog-scenarios.c |   38 +++++++++-----------------------------
 1 files changed, 9 insertions(+), 29 deletions(-)
---
diff --git a/src/dialogs/dialog-scenarios.c b/src/dialogs/dialog-scenarios.c
index be81739..fadd961 100644
--- a/src/dialogs/dialog-scenarios.c
+++ b/src/dialogs/dialog-scenarios.c
@@ -521,29 +521,6 @@ update_comment (ScenariosState *state, const gchar *cells,
 	gtk_text_buffer_set_text (buf, comment, strlen (comment));
 }
 
-static gboolean
-find_scenario_strs (GList *scenarios, gchar *name,
-		    gchar **cells, gchar **comment)
-{
-	static gchar *buf1 = NULL, *buf2 = NULL;
-
-	while (scenarios) {
-		const GnmScenario *scenario = scenarios->data;
-
-		if (strcmp (scenario->name, name) == 0) {
-			g_free (buf1);
-			g_free (buf2);
-
-			*cells = buf1 = gnm_scenario_get_range_str (scenario);
-			*comment = buf2 = g_strdup (scenario->comment);
-			return FALSE;
-		}
-		scenarios = scenarios->next;
-	}
-
-	return TRUE;
-}
-
 static void
 set_selection_state (ScenariosState *state, gboolean f)
 {
@@ -556,14 +533,14 @@ set_selection_state (ScenariosState *state, gboolean f)
 		GtkTreeIter             iter;
 		GtkTreeModel            *model;
 		gchar                   *name;
-		gchar                   *comment = NULL;
-		gchar                   *cells = NULL;
+		gchar                   *cells_txt;
+		GnmScenario             *sc;
 
 		selection = gtk_tree_view_get_selection
 			(GTK_TREE_VIEW
 			 (state->scenario_state->scenarios_treeview));
 		if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
-		return;
+			return;
 		model = gtk_tree_view_get_model
 			(GTK_TREE_VIEW
 			 (state->scenario_state->scenarios_treeview));
@@ -571,9 +548,12 @@ set_selection_state (ScenariosState *state, gboolean f)
 		gtk_tree_model_get (GTK_TREE_MODEL (model), &iter,
 				    0, &name, -1);
 
-		find_scenario_strs (state->base.sheet->scenarios, name,
-				    &cells, &comment);
-		update_comment (state, cells, comment);
+		sc = gnm_sheet_scenario_find (state->base.sheet, name);
+		if (!sc)
+			return;
+		cells_txt = gnm_scenario_get_range_str (sc);
+		update_comment (state, cells_txt, sc->comment);
+		g_free (cells_txt);
 	} else
 		update_comment (state, "", "");
 }



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