Commit 97f47c58 authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder
Browse files

Plug file descriptor leak. (stf_write_func): Constify.

2001-05-07  Morten Welinder  <terra@diku.dk>

	* src/stf.c (stf_write_workbook): Plug file descriptor leak.
	(stf_write_func): Constify.
	(stf_open_and_read): Protect against missing file size after
 	fstat.

2001-05-07  Morten Welinder  <terra@diku.dk>

	* sc.c (sc_parse_cell_name_list): g_free, not free.
parent 32feac4f
Mon May 7 14:07:45 2001 Morten Welinder <welinder@rentec.com>
* src/stf.c (stf_write_workbook): Plug file descriptor leak.
(stf_write_func): Constify.
(stf_open_and_read): Protect against missing file size after
fstat.
2001-05-07 Almer S. Tigelaar <almer@gnome.org>
* src/workbook-edit.c
......
Mon May 7 14:07:45 2001 Morten Welinder <welinder@rentec.com>
* src/stf.c (stf_write_workbook): Plug file descriptor leak.
(stf_write_func): Constify.
(stf_open_and_read): Protect against missing file size after
fstat.
2001-05-07 Almer S. Tigelaar <almer@gnome.org>
* src/workbook-edit.c
......
Mon May 7 14:07:45 2001 Morten Welinder <welinder@rentec.com>
* src/stf.c (stf_write_workbook): Plug file descriptor leak.
(stf_write_func): Constify.
(stf_open_and_read): Protect against missing file size after
fstat.
2001-05-07 Almer S. Tigelaar <almer@gnome.org>
* src/workbook-edit.c
......
Mon May 7 14:07:45 2001 Morten Welinder <welinder@rentec.com>
* src/stf.c (stf_write_workbook): Plug file descriptor leak.
(stf_write_func): Constify.
(stf_open_and_read): Protect against missing file size after
fstat.
2001-05-07 Almer S. Tigelaar <almer@gnome.org>
* src/workbook-edit.c
......
Mon May 7 14:07:45 2001 Morten Welinder <welinder@rentec.com>
* src/stf.c (stf_write_workbook): Plug file descriptor leak.
(stf_write_func): Constify.
(stf_open_and_read): Protect against missing file size after
fstat.
2001-05-07 Almer S. Tigelaar <almer@gnome.org>
* src/workbook-edit.c
......
2001-05-07 Morten Welinder <terra@diku.dk>
* sc.c (sc_parse_cell_name_list): g_free, not free.
2001-03-17 Jody Goldberg <jgoldberg@home.com>
* Release 0.64
......
......@@ -220,7 +220,7 @@ sc_parse_cell_name_list (Sheet *sheet, const char *cell_name_str,
if (!parse_cell_name (buf, &col, &row)){
*error_flag = 1;
free (buf);
g_free (buf);
g_slist_free (cells);
return NULL;
}
......@@ -233,7 +233,7 @@ sc_parse_cell_name_list (Sheet *sheet, const char *cell_name_str,
}
*error_flag = 0;
free (buf);
g_free (buf);
return cells;
}
......
......@@ -68,13 +68,18 @@ stf_open_and_read (const char *filename)
{
struct stat sbuf;
char *data;
int const fd = open (filename, O_RDONLY);
int fd = open (filename, O_RDONLY);
if (fd < 0)
return NULL;
if (fstat(fd, &sbuf) < 0) {
if (fstat (fd, &sbuf) < 0) {
close (fd);
return NULL;
}
/* If we don't know the size, give up. */
if (sbuf.st_size < 0) {
close (fd);
return NULL;
}
......@@ -87,16 +92,16 @@ stf_open_and_read (const char *filename)
if (!data)
return NULL;
/*
* FIXME: read might not read everything in one go.
*/
if (read (fd, data, sbuf.st_size) != sbuf.st_size) {
free (data);
close (fd);
return NULL;
}
close (fd);
return data;
}
......@@ -263,10 +268,8 @@ stf_open_for_write (IOContext *context, const char *filename)
* Return value: TRUE on successful write, FALSE otherwise
**/
static gboolean
stf_write_func (char *string, gpointer data)
stf_write_func (const char *string, FILE *f)
{
FILE *f = data;
if (fputs (string, f) >= 0)
return TRUE;
else
......@@ -305,6 +308,7 @@ stf_write_workbook (FileSaver const *fs, IOContext *context, WorkbookView *wb_vi
stf_export_options_set_write_callback (result->export_options,
(StfEWriteFunc) stf_write_func, (gpointer) f);
fclose (f);
if (stf_export (result->export_options) == FALSE) {
......@@ -316,8 +320,6 @@ stf_write_workbook (FileSaver const *fs, IOContext *context, WorkbookView *wb_vi
stf_export_dialog_result_free (result);
fclose (f);
return TRUE;
} else
return FALSE;
......@@ -332,7 +334,7 @@ stf_write_workbook (FileSaver const *fs, IOContext *context, WorkbookView *wb_vi
void
stf_init (void)
{
char *desc;
const char *desc;
desc = _("Text File import");
file_format_register_open (1, desc, NULL, stf_read_workbook);
......
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