Commit 82da7fbe authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Plug leak.

2000-06-14  Morten Welinder  <terra@diku.dk>

	* ms-formula-write.c (ms_excel_write_formula): Plug leak.

	* ms-excel-write.c (ms_excel_check_write): In case of error, clear
 	out the state.
	(ms_excel_write_free_state): "New" function.
	(write_workbook): Don't free workbook here.
	(ms_excel_write_workbook): Do it here and plug a leak.

	* boot.c (excel_save): Free the state.
parent 0a8474ca
......@@ -102,9 +102,9 @@ excel_load (CommandContext *context, Workbook *wb, const char *filename)
/*
* Here's why the state which is carried from excel_check_write to
* ms_excel_write_workbook is void *: The state is actually an
* ExcelWorksheet * as defined in ms-excel-write.h. But we can't
* ExcelWorkbook * as defined in ms-excel-write.h. But we can't
* import that definition here: There's a different definition of
* ExcelWorksheet in ms-excel-read.h.
* ExcelWorkbook in ms-excel-read.h.
*/
static int
excel_save (CommandContext *context, Workbook *wb, const char *filename,
......@@ -135,6 +135,7 @@ excel_save (CommandContext *context, Workbook *wb, const char *filename,
gnumeric_error_save (context, str);
ms_ole_destroy (&f);
ms_excel_write_free_state (state);
g_free (str);
return -1;
}
......
......@@ -31,14 +31,16 @@ extern int ms_excel_read_workbook (CommandContext *context,
/*
* Here's why the state which is carried from excel_check_write to
* ms_excel_write_workbook is void *: The state is actually an
* ExcelWorksheet * as defined in ms-excel-write.h. But we can't
* ExcelWorkbook * as defined in ms-excel-write.h. But we can't
* import that definition here: There's a different definition of
* ExcelWorksheet in ms-excel-read.h.
* ExcelWorkbook in ms-excel-read.h.
*/
extern int ms_excel_check_write (CommandContext *context, void **state,
Workbook *wb, MsBiffVersion ver);
extern int ms_excel_write_workbook (CommandContext *context, MsOle *file,
void *state, MsBiffVersion ver);
void ms_excel_write_free_state (void *state);
/* We need to use these for both read and write */
typedef struct {
......
......@@ -3345,8 +3345,6 @@ write_workbook (BiffPut *bp, ExcelWorkbook *wb, MsBiffVersion ver)
s->streamPos);
}
/* End Finalised workbook */
free_workbook (wb);
}
/*
......@@ -3423,8 +3421,10 @@ ms_excel_check_write (CommandContext *context, void **state, Workbook *gwb,
ret = pre_pass (context, wb);
cleanup:
if (ret != 0)
if (ret != 0) {
free_workbook (wb);
*state = NULL;
}
g_list_free (sheets);
return ret;
......@@ -3450,6 +3450,7 @@ ms_excel_write_workbook (CommandContext *context, MsOle *file, void *state,
result = ms_ole_stream_open (&str, file, "/", strname, 'w');
if (result != MS_OLE_ERR_OK) {
free_workbook (wb);
gnumeric_error_save
(context, _("Can't open stream for writing\n"));
return -1;
......@@ -3458,6 +3459,7 @@ ms_excel_write_workbook (CommandContext *context, MsOle *file, void *state,
bp = ms_biff_put_new (str);
write_workbook (bp, wb, ver);
free_workbook (wb);
/* Kludge to make sure the file is a Big Block file */
while (bp->pos->size < 0x1000) {
......@@ -3477,3 +3479,10 @@ ms_excel_write_workbook (CommandContext *context, MsOle *file, void *state,
return 0;
}
void
ms_excel_write_free_state (void *state)
{
if (state) free_workbook (state);
}
......@@ -16,6 +16,7 @@
#include <gnome.h>
#include "gnumeric.h"
#include "gutils.h"
#include "func.h"
#include "value.h"
......@@ -62,7 +63,8 @@ struct _FormulaCacheEntry {
void
ms_formula_cache_init (ExcelSheet *sheet)
{
sheet->formula_cache = g_hash_table_new (g_str_hash, g_str_equal);
sheet->formula_cache = g_hash_table_new (gnumeric_strcase_hash,
gnumeric_strcase_equal);
}
static gboolean
......@@ -813,5 +815,7 @@ ms_excel_write_formula (BiffPut *bp, ExcelSheet *sheet, ExprTree *expr,
write_arrays (pd);
}
g_free (pd);
return len;
}
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