commit b848ca0ae6f4c88a7139d7753ad418b8e005980e
Author: Oppen <mrugiero@gmail.com>
Date:   Thu Dec 12 04:57:46 2013 -0300

    [cppcheck] Fix some leaks and null dereferences.

diff --git a/plugins/excel/ms-excel-read.c b/plugins/excel/ms-excel-read.c
index b080649..8f31aae 100644
--- a/plugins/excel/ms-excel-read.c
+++ b/plugins/excel/ms-excel-read.c
@@ -1614,11 +1614,12 @@ static void
 excel_read_FONT (BiffQuery *q, GnmXLImporter *importer)
 {
 	MsBiffVersion const ver = importer->ver;
-	ExcelFont *fd = g_new (ExcelFont, 1);
+	ExcelFont *fd;
 	guint16 data;
 	guint8 data1;
 
 	XL_CHECK_CONDITION (q->length >= 4);
+	fd = g_new (ExcelFont, 1);
 	fd->height = GSF_LE_GET_GUINT16 (q->data + 0);
 	data = GSF_LE_GET_GUINT16 (q->data + 2);
 	fd->italic = (data & 0x2) == 0x2;
diff --git a/plugins/excel/ms-obj.c b/plugins/excel/ms-obj.c
index 629e08c..c528636 100644
--- a/plugins/excel/ms-obj.c
+++ b/plugins/excel/ms-obj.c
@@ -886,6 +886,7 @@ ms_obj_read_pre_biff8_obj (BiffQuery *q, MSContainer *c, MSObj *obj)
 			}
 		}
 	}
+	g_free(anchor);
 	return FALSE;
 }
 
diff --git a/plugins/excelplugins/ExcelTestModule.c b/plugins/excelplugins/ExcelTestModule.c
index 26a57ba..9b800e0 100644
--- a/plugins/excelplugins/ExcelTestModule.c
+++ b/plugins/excelplugins/ExcelTestModule.c
@@ -110,8 +110,8 @@ static void destruct_xloper(XLOPER*x){
 		case xltypeInt:							break;
 		default:		unsupported_xloper_type(x);
 		}
+		x->xltype=xltypeNil;
 	}
-	x->xltype=xltypeNil;
 }
 
 static void copy_construct_xloper(XLOPER*x,const XLOPER*y){
diff --git a/src/cellspan.c b/src/cellspan.c
index 0a472c6..01fd6ce 100644
--- a/src/cellspan.c
+++ b/src/cellspan.c
@@ -265,7 +265,7 @@ cell_calc_span (GnmCell const *cell, int *col1, int *col2)
 		if (gnm_style_get_align_h (style) == GNM_HALIGN_GENERAL && dir == PANGO_DIRECTION_RTL)
 			h_align = GNM_HALIGN_RIGHT;
 		indented_w += gnm_cell_rendered_offset (cell);
-		if (sheet->text_is_rtl)
+		if (sheet != NULL && sheet->text_is_rtl)
 			h_align = (h_align == GNM_HALIGN_LEFT) ? GNM_HALIGN_RIGHT : GNM_HALIGN_LEFT;
 	}
 
diff --git a/src/commands.c b/src/commands.c
index d8d1642..0395c4e 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -2959,7 +2959,7 @@ get_new_objects (Sheet *sheet, GSList *old)
 
 		old = old->next;
 
-		if (c == 0) {
+		if (p && c == 0) {
 			GSList *next = p->next;
 			if (last)
 				last->next = next;
diff --git a/src/dialogs/dialog-analysis-tool-chi-squared.c b/src/dialogs/dialog-analysis-tool-chi-squared.c
index f8608cd..aff98d0 100644
--- a/src/dialogs/dialog-analysis-tool-chi-squared.c
+++ b/src/dialogs/dialog-analysis-tool-chi-squared.c
@@ -222,7 +222,10 @@ dialog_chi_square_tool (WBCGtk *wbcg, Sheet *sheet, gboolean independence)
 			      NULL,
 			      G_CALLBACK (chi_squared_tool_update_sensitivity_cb),
 			      GNM_EE_SINGLE_RANGE))
+	{
+		g_free(state);
 		return 0;
+	}
 
 	if (independence)
 		type ="test-of-independence";
diff --git a/src/dialogs/dialog-analysis-tool-frequency.c b/src/dialogs/dialog-analysis-tool-frequency.c
index 65e48f0..99c5d5c 100644
--- a/src/dialogs/dialog-analysis-tool-frequency.c
+++ b/src/dialogs/dialog-analysis-tool-frequency.c
@@ -261,7 +261,10 @@ dialog_frequency_tool (WBCGtk *wbcg, Sheet *sheet)
 			      G_CALLBACK (frequency_tool_ok_clicked_cb), NULL,
 			      G_CALLBACK (frequency_tool_update_sensitivity_cb),
 			      0))
+	{
+		g_free(state);
 		return 0;
+	}
 
 	state->predetermined_button = tool_setup_update
 		(&state->base, "pre_determined_button",
diff --git a/src/dialogs/dialog-analysis-tool-kaplan-meier.c b/src/dialogs/dialog-analysis-tool-kaplan-meier.c
index 93f7f41..15e267c 100644
--- a/src/dialogs/dialog-analysis-tool-kaplan-meier.c
+++ b/src/dialogs/dialog-analysis-tool-kaplan-meier.c
@@ -629,7 +629,10 @@ dialog_kaplan_meier_tool (WBCGtk *wbcg, Sheet *sheet)
 			      G_CALLBACK (kaplan_meier_tool_ok_clicked_cb), NULL,
 			      G_CALLBACK (kaplan_meier_tool_update_sensitivity_cb),
 			      0))
+	{
+		g_free(state);
 		return 0;
+	}
 
 
 
diff --git a/src/dialogs/dialog-analysis-tool-normality.c b/src/dialogs/dialog-analysis-tool-normality.c
index 95c3e27..8974438 100644
--- a/src/dialogs/dialog-analysis-tool-normality.c
+++ b/src/dialogs/dialog-analysis-tool-normality.c
@@ -204,7 +204,10 @@ dialog_normality_tool (WBCGtk *wbcg, Sheet *sheet)
 			      G_CALLBACK (normality_tool_ok_clicked_cb), NULL,
 			      G_CALLBACK (normality_tool_update_sensitivity_cb),
 			      0))
+	{
+		g_free(state);
 		return 0;
+	}
 
 
 	state->alpha_entry = tool_setup_update
diff --git a/src/dialogs/dialog-analysis-tool-one-mean.c b/src/dialogs/dialog-analysis-tool-one-mean.c
index 6fbb742..57d4d26 100644
--- a/src/dialogs/dialog-analysis-tool-one-mean.c
+++ b/src/dialogs/dialog-analysis-tool-one-mean.c
@@ -228,7 +228,10 @@ dialog_one_mean_test_tool (WBCGtk *wbcg, Sheet *sheet)
 			      NULL,
 			      G_CALLBACK (one_mean_test_tool_update_sensitivity_cb),
 			      0))
+	{
+		g_free(state);
 		return 0;
+	}
 
 
 	state->alpha_entry = tool_setup_update
diff --git a/src/dialogs/dialog-analysis-tool-sign-test.c b/src/dialogs/dialog-analysis-tool-sign-test.c
index 9c70930..f91294c 100644
--- a/src/dialogs/dialog-analysis-tool-sign-test.c
+++ b/src/dialogs/dialog-analysis-tool-sign-test.c
@@ -261,7 +261,10 @@ dialog_sign_test_two_tool (WBCGtk *wbcg, Sheet *sheet, signtest_type type)
 			      NULL,
 			      G_CALLBACK (sign_test_two_tool_update_sensitivity_cb),
 			      GNM_EE_SINGLE_RANGE))
+	{
+		g_free(state);
 		return 0;
+	}
 
 
 	state->alpha_entry = tool_setup_update
@@ -406,7 +409,10 @@ dialog_sign_test_tool (WBCGtk *wbcg, Sheet *sheet, signtest_type type)
 			      NULL,
 			      G_CALLBACK (sign_test_tool_update_sensitivity_cb),
 			      0))
+	{
+		g_free(state);
 		return 0;
+	}
 
 
 	state->alpha_entry = tool_setup_update
diff --git a/src/dialogs/dialog-analysis-tools.c b/src/dialogs/dialog-analysis-tools.c
index 88eaa05..36f6212 100644
--- a/src/dialogs/dialog-analysis-tools.c
+++ b/src/dialogs/dialog-analysis-tools.c
@@ -1234,7 +1234,10 @@ dialog_descriptive_stat_tool (WBCGtk *wbcg, Sheet *sheet)
 			      G_CALLBACK (cb_desc_stat_tool_ok_clicked), NULL,
 			      G_CALLBACK (desc_stat_tool_update_sensitivity_cb),
 			      0))
+	{
+		g_free(state);
 		return 0;
+	}
 
 	state->summary_stats_button  = go_gtk_builder_get_widget
 		(state->base.gui, "summary_stats_button");
@@ -1616,7 +1619,10 @@ dialog_ttest_tool (WBCGtk *wbcg, Sheet *sheet, ttest_type test)
 			      G_CALLBACK (ttest_tool_ok_clicked_cb), NULL,
 			      G_CALLBACK (ttest_update_sensitivity_cb),
 			      GNM_EE_SINGLE_RANGE))
+	{
+		g_free(state);
 		return 0;
+	}
 
 	state->paired_button  = go_gtk_builder_get_widget (state->base.gui, "paired-button");
 	state->unpaired_button  = go_gtk_builder_get_widget (state->base.gui, "unpaired-button");
@@ -1803,7 +1809,10 @@ dialog_ftest_tool (WBCGtk *wbcg, Sheet *sheet)
 			      G_CALLBACK (ftest_tool_ok_clicked_cb), NULL,
 			      G_CALLBACK (ftest_update_sensitivity_cb),
 			      GNM_EE_SINGLE_RANGE))
+	{
+		g_free(state);
 		return 0;
+	}
 
 	state->alpha_entry = go_gtk_builder_get_widget (state->base.gui, "one_alpha");
 	float_to_entry (GTK_ENTRY (state->alpha_entry), 0.05);
@@ -2058,7 +2067,10 @@ dialog_sampling_tool (WBCGtk *wbcg, Sheet *sheet)
 			      G_CALLBACK (sampling_tool_ok_clicked_cb), NULL,
 			      G_CALLBACK (sampling_tool_update_sensitivity_cb),
 			      0))
+	{
+		g_free(state);
 		return 0;
+	}
 
 	state->periodic_button  = go_gtk_builder_get_widget (state->base.gui, "periodic-button");
 	state->random_button  = go_gtk_builder_get_widget (state->base.gui, "random-button");
@@ -2417,7 +2429,10 @@ dialog_regression_tool (WBCGtk *wbcg, Sheet *sheet)
 			      G_CALLBACK (regression_tool_ok_clicked_cb), NULL,
 			      G_CALLBACK (regression_tool_update_sensitivity_cb),
 			      GNM_EE_SINGLE_RANGE))
+	{
+		g_free(state);
 		return 0;
+	}
 
 	state->confidence_entry = go_gtk_builder_get_widget (state->base.gui, "confidence-entry");
 	float_to_entry (GTK_ENTRY (state->confidence_entry), 0.95);
@@ -2727,7 +2742,10 @@ dialog_exp_smoothing_tool (WBCGtk *wbcg, Sheet *sheet)
 			      NULL,
 			      G_CALLBACK (exp_smoothing_tool_update_sensitivity_cb),
 			      0))
+	{
+		g_free(state);
 		return 0;
+	}
 
 	state->damping_fact_entry = go_gtk_builder_get_widget (state->base.gui,
 							  "damping-fact-spin");
@@ -3097,7 +3115,10 @@ dialog_average_tool (WBCGtk *wbcg, Sheet *sheet)
 			      G_CALLBACK (average_tool_ok_clicked_cb), NULL,
 			      G_CALLBACK (average_tool_update_sensitivity_cb),
 			      0))
+	{
+		g_free(state);
 		return 0;
+	}
 
 	state->interval_entry = go_gtk_builder_get_widget (state->base.gui, "interval-entry");
 	int_to_entry (GTK_ENTRY (state->interval_entry), 3);
@@ -3364,7 +3385,10 @@ dialog_histogram_tool (WBCGtk *wbcg, Sheet *sheet)
 			      G_CALLBACK (histogram_tool_ok_clicked_cb), NULL,
 			      G_CALLBACK (histogram_tool_update_sensitivity_cb),
 			      0))
+	{
+		g_free(state);
 		return 0;
+	}
 
 	state->predetermined_button = GTK_WIDGET (go_gtk_builder_get_widget
 						  (state->base.gui,
@@ -3543,7 +3567,10 @@ dialog_anova_single_factor_tool (WBCGtk *wbcg, Sheet *sheet)
 			      NULL,
 			      G_CALLBACK (anova_single_tool_update_sensitivity_cb),
 			      0))
+	{
+		g_free(state);
 		return 0;
+	}
 
 	state->alpha_entry = go_gtk_builder_get_widget (state->base.gui,
 						   "alpha-entry");
@@ -3772,7 +3799,10 @@ dialog_anova_two_factor_tool (WBCGtk *wbcg, Sheet *sheet)
 			      NULL,
 			      G_CALLBACK (anova_two_factor_tool_update_sensitivity_cb),
 			      GNM_EE_SINGLE_RANGE))
+	{
+		g_free(state);
 		return 0;
+	}
 
 	state->alpha_entry = go_gtk_builder_get_widget (state->base.gui,
 						   "alpha-entry");
diff --git a/src/dialogs/dialog-doc-metadata.c b/src/dialogs/dialog-doc-metadata.c
index 8839a86..fa6aeec 100644
--- a/src/dialogs/dialog-doc-metadata.c
+++ b/src/dialogs/dialog-doc-metadata.c
@@ -1829,6 +1829,7 @@ cb_dialog_doc_metadata_ppt_name_changed (G_GNUC_UNUSED GtkEntry          *entry,
 	g_free (name_trimmed);
 
 	if (enable)
+		g_free (str);
 		return cb_dialog_doc_metadata_ppt_changed (NULL, NULL, state);
 	else {
 		gtk_widget_set_sensitive (GTK_WIDGET (state->add_button), FALSE);
diff --git a/src/dialogs/dialog-scenarios.c b/src/dialogs/dialog-scenarios.c
index 3117506..94d800d 100644
--- a/src/dialogs/dialog-scenarios.c
+++ b/src/dialogs/dialog-scenarios.c
@@ -399,7 +399,10 @@ dialog_scenario_add (WBCGtk *wbcg)
 			      G_CALLBACK (scenario_add_ok_clicked_cb), NULL,
 			      G_CALLBACK (scenario_add_update_sensitivity_cb),
 			      GNM_EE_SHEET_OPTIONAL))
+	{
+		g_free (state);
 		return;
+	}
 
 	state->name_entry = go_gtk_builder_get_widget (state->base.gui, "name_entry");
 	if (state->name_entry == NULL)
diff --git a/src/sf-bessel.c b/src/sf-bessel.c
index 119baa4..b7e89a0 100644
--- a/src/sf-bessel.c
+++ b/src/sf-bessel.c
@@ -1810,6 +1810,7 @@ static gnm_float bessel_y(gnm_float x, gnm_float alpha)
     Y_bessel(&x, &alpha, &nb, by, &ncalc);
     if(ncalc != nb) {/* error input */
 	if(ncalc == -1)
+            free(by);
 	    return gnm_pinf;
 	else if(ncalc < -1)
 	    MATHLIB_WARNING4(("bessel_y(%" GNM_FORMAT_g "): ncalc (=%ld) != nb (=%ld); alpha=%" GNM_FORMAT_g ". Arg. out of range?\n"),
