Commit 64fe46cb authored by Morten Welinder's avatar Morten Welinder
Browse files

More backporting.

	* Fix crash on xml load.  [#323888]
	* Fix file corruption on saving scenarios.  [#323927]
	* Fix a pile of leaks in solver and scenario saving and loading.
	* Fix leaks in solver dialog.
	* Fix parser leak.  [#301127]
parent 70636c63
2005-12-13 Morten Welinder <terra@gnome.org>
* src/parser.y (build_set): Make this function unregister argument
on success like all the other build_* functions. Fix caller to
not leak in error case. Fixes #301127.
2005-12-13 Morten Welinder <terra@gnome.org>
* src/xml-io.c (xml_read_scenarios): Plug leak.
* src/xml-sax-write.c (xml_write_scenarios): Add missing
gsf_xml_out_end_element corrupting files.
2005-12-12 Morten Welinder <terra@gnome.org>
* src/xml-io.c (xml_node_get_value): Add protections against file
corruption. Fixes crash from #323888.
2005-12-01 Eduardo Lima <eduardo.lima@indt.org.br>
* wbcg-actions.c (cb_view_zoom_in): Changed name to cb_view_zoom_out.
......
......@@ -12,6 +12,11 @@ Morten:
* Fix TRIM for non-ASCII case with spaces at end.
* Improve Excel compatibility of BIN2DEC, BIN2HEX, and
BIN2OCT. [#323787]
* Fix crash on xml load. [#323888]
* Fix file corruption on saving scenarios. [#323927]
* Fix a pile of leaks in solver and scenario saving and loading.
* Fix leaks in solver dialog.
* Fix parser leak. [#301127]
Nick Lamb:
* Fix CONVERT crash. [#323678]
......
2005-12-13 Morten Welinder <terra@gnome.org>
* src/parser.y (build_set): Make this function unregister argument
on success like all the other build_* functions. Fix caller to
not leak in error case. Fixes #301127.
2005-12-13 Morten Welinder <terra@gnome.org>
* src/xml-io.c (xml_read_scenarios): Plug leak.
* src/xml-sax-write.c (xml_write_scenarios): Add missing
gsf_xml_out_end_element corrupting files.
2005-12-12 Morten Welinder <terra@gnome.org>
* src/xml-io.c (xml_node_get_value): Add protections against file
corruption. Fixes crash from #323888.
2005-12-01 Eduardo Lima <eduardo.lima@indt.org.br>
* wbcg-actions.c (cb_view_zoom_in): Changed name to cb_view_zoom_out.
......
2005-12-13 Morten Welinder <terra@gnome.org>
* dialog-solver.c (check_int_constraints): Plug leak.
(solver_add_scenario): Plug leaks. Constify.
(cb_dialog_solve_clicked): Use solver_constraint_destroy.
(cb_destroy): Remove.
2005-11-14 Jody Goldberg <jody@gnome.org>
* Release 1.6.1
......
......@@ -527,20 +527,31 @@ check_int_constraints (GnmValue *input_range, SolverState *state)
{
GtkTreeModel *store;
GtkTreeIter iter;
const constraint_t *a_constraint;
const gchar *text;
store = gtk_tree_view_get_model (state->constraint_list);
if (gtk_tree_model_get_iter_first (store, &iter))
do {
const constraint_t *a_constraint;
gchar *text;
gtk_tree_model_get (store, &iter, 0, &text, 1, &a_constraint, -1);
if (a_constraint == NULL)
if (a_constraint == NULL) {
g_free (text);
break;
}
if ((a_constraint->type != SolverINT) &&
(a_constraint->type != SolverBOOL))
(a_constraint->type != SolverBOOL)) {
g_free (text);
continue;
if (!global_range_contained (state->sheet, a_constraint->lhs_value, input_range))
}
if (!global_range_contained (state->sheet,
a_constraint->lhs_value,
input_range))
return text;
g_free (text);
} while (gtk_tree_model_iter_next (store, &iter));
return NULL;
}
......@@ -665,19 +676,6 @@ save_original_values (GSList *input_cells)
return ov;
}
/**
* cb_destroy:
* @data:
* @user_data:
*
*
**/
static void
cb_destroy (gpointer data, G_GNUC_UNUSED gpointer user_data)
{
g_free (data);
}
/* Returns FALSE if the reports deleted the current sheet
* and forced the dialog to die */
......@@ -790,18 +788,18 @@ solver_reporting (SolverState *state, SolverResults *res, const gchar *errmsg)
}
static void
solver_add_scenario (SolverState *state, SolverResults *res, gchar *name)
solver_add_scenario (SolverState *state, SolverResults *res, const gchar *name)
{
SolverParameters *param = res->param;
GnmValue *input_range;
GnmValue *input_range;
const gchar *comment = _("Optimal solution created by solver.\n");
scenario_t *scenario;
input_range = gnm_expr_entry_parse_as_value (state->change_cell_entry,
state->sheet);
scenario_add_new (name, input_range, g_strdup (param->input_entry_str),
g_strdup (comment), state->sheet, &scenario);
scenario_add_new (name, input_range, param->input_entry_str,
comment, state->sheet, &scenario);
scenario_add (state->sheet, scenario);
if (input_range != NULL)
value_release (input_range);
......@@ -956,11 +954,10 @@ cb_dialog_solve_clicked (G_GNUC_UNUSED GtkWidget *button,
conv.sheet = state->sheet;
conv.c_listing = state->constraint_list;
convert_constraint_format (&conv);
if (param->constraints != NULL) {
g_slist_foreach (param->constraints, cb_destroy, NULL);
g_slist_free (param->constraints);
param->constraints = NULL;
}
g_slist_foreach (param->constraints,
(GFunc)solver_constraint_destroy,
NULL);
g_slist_free (param->constraints);
param->constraints = conv.c_list;
if (param->constraints == NULL) {
go_gtk_notice_nonmodal_dialog
......
......@@ -379,6 +379,7 @@ build_set (GnmExprList *list)
return NULL;
}
unregister_allocation (list);
return register_expr_allocation (gnm_expr_new_set (list));
}
......@@ -563,8 +564,8 @@ exp: CONSTANT { $$ = $1; }
state->ptr-2, 2);
YYERROR;
} else {
unregister_allocation ($2);
if ($2->next == NULL) {
unregister_allocation ($2);
$$ = register_expr_allocation ($2->data);
/* NOTE : free list not content */
gnm_expr_list_free ($2);
......@@ -724,7 +725,7 @@ cellref: RANGEREF { $$ = $1; }
arg_list: exp {
unregister_allocation ($1);
$$ = g_slist_prepend (NULL, $1);
$$ = gnm_expr_list_prepend (NULL, $1);
register_expr_list_allocation ($$);
}
| exp SEPARATOR arg_list {
......@@ -735,7 +736,7 @@ arg_list: exp {
if (tmp == NULL)
tmp = gnm_expr_list_prepend (NULL, gnm_expr_new_constant (value_new_empty ()));
$$ = g_slist_prepend (tmp, $1);
$$ = gnm_expr_list_prepend (tmp, $1);
register_expr_list_allocation ($$);
}
| SEPARATOR arg_list {
......
......@@ -254,8 +254,9 @@ GnmCell *solver_get_target_cell (Sheet *sheet);
/* Returns a pointer to a input variable cell. */
GnmCell *solver_get_input_var (SolverResults *res, int n);
/* Retruns a pointer to a constraint. */
/* Returns a pointer to a constraint. */
SolverConstraint* solver_get_constraint (SolverResults *res, int n);
void solver_constraint_destroy (SolverConstraint *c);
void solver_insert_cols (Sheet *sheet, int col, int count);
void solver_insert_rows (Sheet *sheet, int row, int count);
......@@ -271,6 +272,7 @@ void solver_delete_cols (Sheet *sheet, int col, int count);
#define solver_insert_rows(sheet, row, count) do {} while(0)
#define solver_delete_cols(sheet, col, count) do {} while(0)
#define solver_delete_rows(sheet, row, count) do {} while(0)
#define solver_constraint_destroy(c) do {} while(0)
#endif
......
2005-12-13 Morten Welinder <terra@gnome.org>
* scenarios.c (scenario_add_new): Constify.
(collect_values): Initialize changing_cells with NULL.
2005-11-14 Jody Goldberg <jody@gnome.org>
* Release 1.6.1
......
......@@ -166,7 +166,7 @@ collect_values (Sheet *sheet, scenario_t *s, GnmValueRange *range)
rows = s->range.end.row - s->range.start.row + 1;
cols = s->range.end.col - s->range.start.col + 1;
s->changing_cells = g_new (GnmValue *, rows * cols);
s->changing_cells = g_new0 (GnmValue *, rows * cols);
cb.expr_flag = FALSE;
cb.sheet = sheet;
......@@ -177,10 +177,10 @@ collect_values (Sheet *sheet, scenario_t *s, GnmValueRange *range)
/* Doesn't actually add the new scenario into the sheet's scenario list. */
gboolean
scenario_add_new (gchar *name,
scenario_add_new (const gchar *name,
GnmValue *changing_cells,
gchar *cell_sel_str,
gchar *comment,
const gchar *cell_sel_str,
const gchar *comment,
Sheet *sheet,
scenario_t **new_scenario)
{
......
......@@ -41,10 +41,10 @@ scenario_t *scenario_show (WorkbookControl *wbc,
scenario_t *scenario,
scenario_t *old_values,
data_analysis_output_t *dao);
gboolean scenario_add_new (gchar *name,
gboolean scenario_add_new (const gchar *name,
GnmValue *changing_cells,
gchar *cell_sel_str,
gchar *comment,
const gchar *cell_sel_str,
const gchar *comment,
Sheet *sheet, scenario_t **new_scenario);
void scenario_add (Sheet *sheet, scenario_t *scenario);
gboolean scenario_mark_deleted (GList *scenarios, gchar *name);
......
2005-12-13 Morten Welinder <terra@gnome.org>
* solver.c (solver_param_destroy): Destroy and free the list of
constaints. Free the list of input cells.
(solver_constraint_destroy): New function.
2005-11-14 Jody Goldberg <jody@gnome.org>
* Release 1.6.1
......
......@@ -74,6 +74,11 @@ solver_param_new (void)
void
solver_param_destroy (SolverParameters *sp)
{
g_slist_foreach (sp->constraints,
(GFunc)solver_constraint_destroy,
NULL);
g_slist_free (sp->constraints);
g_list_free (sp->input_cells);
g_free (sp->input_entry_str);
g_free (sp->options.scenario_name);
g_free (sp);
......@@ -169,6 +174,13 @@ solver_get_constraint (SolverResults *res, int n)
return res->constraints_array[n];
}
void
solver_constraint_destroy (SolverConstraint *c)
{
g_free (c->str);
g_free (c);
}
/* ------------------------------------------------------------------------- */
static SolverConstraint*
......@@ -563,7 +575,7 @@ check_program_definition_failures (Sheet *sheet,
param->n_bool_constraints = 0;
i = 0;
for (c = param->constraints; c ; c = c->next) {
SolverConstraint *sc = (SolverConstraint *) c->data;
SolverConstraint *sc = c->data;
if (sc->type == SolverINT)
param->n_int_constraints +=
......@@ -580,7 +592,7 @@ check_program_definition_failures (Sheet *sheet,
param->n_total_constraints);
i = 0;
for (c = param->constraints; c ; c = c->next) {
SolverConstraint *sc = (SolverConstraint *) c->data;
SolverConstraint *sc = c->data;
if (sc->rows == 1 && sc->cols == 1)
constraints_array[i++] = sc;
......@@ -947,5 +959,3 @@ solver_delete_cols (Sheet *sheet, int col, int count)
c->type, c->cols, c->rows);
}
}
......@@ -185,8 +185,18 @@ xml_node_get_value (xmlNodePtr node, char const *name)
gchar *vstr;
str = xml_node_get_cstr (node, name);
if (!str) {
/* This happens because the sax writer as-of 1.6.1 does
not write these fields. */
return value_new_error_NA (NULL);
}
type = (GnmValueType) atoi (str);
vstr = g_strrstr (str, ":") + 1;
if (!vstr) {
g_warning ("File corruption [%s] [%s]", name, str);
return value_new_error_NA (NULL);
}
value = value_new_from_string (type, vstr, NULL, FALSE);
xmlFree (str);
......@@ -1615,7 +1625,7 @@ xml_read_scenarios (XmlParseContext *ctxt, xmlNodePtr tree)
g_string_append_printf (name, "V%d", i);
s->changing_cells [i] = xml_node_get_value (child,
name->str);
g_string_free (name, FALSE);
g_string_free (name, TRUE);
}
sheet->scenarios = g_list_append (sheet->scenarios, s);
......
......@@ -951,12 +951,7 @@ xml_write_solver (GnmOutputXML *state)
static void
xml_write_scenarios (GnmOutputXML *state)
{
scenario_t const *s;
GList *ptr;
#if 0
GString *name;
int i, cols, rows;
#endif
if (state->sheet->scenarios == NULL)
return;
......@@ -964,7 +959,10 @@ xml_write_scenarios (GnmOutputXML *state)
gsf_xml_out_start_element (state->output, GNM "Scenarios");
for (ptr = state->sheet->scenarios ; ptr != NULL ; ptr = ptr->next) {
s = (scenario_t const *)ptr->data;
scenario_t const *s = (scenario_t const *)ptr->data;
#if 0
int i, cols, rows;
#endif
gsf_xml_out_start_element (state->output, GNM "Scenario");
gsf_xml_out_add_cstr (state->output, "Name", s->name);
......@@ -980,13 +978,15 @@ xml_write_scenarios (GnmOutputXML *state)
rows = range_height (&s->range);
cols = range_width (&s->range);
for (i = 0; i < cols * rows; i++) {
name = g_string_new (NULL);
GString *name = g_string_new (NULL);
g_string_append_printf (name, "V%d", i);
xml_node_set_value (scen, name->str,
s->changing_cells [i]);
g_string_free (name, FALSE);
g_string_free (name, TRUE);
}
#endif
gsf_xml_out_end_element (state->output); /* </gnm:Scenario> */
}
gsf_xml_out_end_element (state->output); /* </gnm:Scenarios> */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment