projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fewer memory leaks
[pspp]
/
src
/
data
/
ods-reader.c
diff --git
a/src/data/ods-reader.c
b/src/data/ods-reader.c
index cb16dbc6944187ea0312fe82f135c85623ea02df..a36a020a0b063eb4b31ab84c94838ec071240b5c 100644
(file)
--- a/
src/data/ods-reader.c
+++ b/
src/data/ods-reader.c
@@
-67,14
+67,15
@@
ods_open_reader (const struct spreadsheet_read_options *opts,
#include "gl/xalloc.h"
static void ods_file_casereader_destroy (struct casereader *, void *);
#include "gl/xalloc.h"
static void ods_file_casereader_destroy (struct casereader *, void *);
-
static struct ccase *ods_file_casereader_read (struct casereader *, void *);
static struct ccase *ods_file_casereader_read (struct casereader *, void *);
+static struct casereader *ods_file_casereader_clone (struct casereader *, void *);
+
static const struct casereader_class ods_file_casereader_class =
{
ods_file_casereader_read,
ods_file_casereader_destroy,
static const struct casereader_class ods_file_casereader_class =
{
ods_file_casereader_read,
ods_file_casereader_destroy,
-
NULL
,
+
ods_file_casereader_clone
,
NULL,
};
NULL,
};
@@
-105,6
+106,7
@@
struct ods_reader
struct spreadsheet spreadsheet;
struct zip_reader *zreader;
xmlTextReaderPtr xtr;
struct spreadsheet spreadsheet;
struct zip_reader *zreader;
xmlTextReaderPtr xtr;
+ int ref_cnt;
enum reader_state state;
int row;
enum reader_state state;
int row;
@@
-113,7
+115,7
@@
struct ods_reader
int current_sheet;
xmlChar *current_sheet_name;
int current_sheet;
xmlChar *current_sheet_name;
-
const
xmlChar *target_sheet_name;
+ xmlChar *target_sheet_name;
int target_sheet_index;
int target_sheet_index;
@@
-136,6
+138,26
@@
struct ods_reader
struct string ods_errs;
};
struct string ods_errs;
};
+void
+ods_destroy (struct spreadsheet *s)
+{
+ struct ods_reader *r = s;
+ if (--r->ref_cnt == 0)
+ {
+ int i;
+
+ for (i = 0; i < r->n_allocated_sheets; ++i)
+ {
+ xmlFree (r->sheets[i].name);
+ }
+
+ zip_reader_destroy (r->zreader);
+ free (r->sheets);
+ free (r);
+ }
+}
+
+
static bool
reading_target_sheet (const struct ods_reader *r)
static bool
reading_target_sheet (const struct ods_reader *r)
@@
-206,6
+228,16
@@
ods_get_sheet_range (struct spreadsheet *s, int n)
}
}
+static struct casereader *
+ods_file_casereader_clone (struct casereader *r_, void *s)
+{
+ struct ods_reader *r = r_;
+
+ printf ("%s:%d CLONE reffing %p %d\n", __FILE__, __LINE__, s, r->ref_cnt);
+
+ return r_;
+}
+
static void
ods_file_casereader_destroy (struct casereader *reader UNUSED, void *r_)
{
static void
ods_file_casereader_destroy (struct casereader *reader UNUSED, void *r_)
{
@@
-227,9
+259,16
@@
ods_file_casereader_destroy (struct casereader *reader UNUSED, void *r_)
caseproto_unref (r->proto);
caseproto_unref (r->proto);
- // free (r);
+ xmlFree (r->current_sheet_name);
+ xmlFree (r->target_sheet_name);
+
+ ods_destroy (r);
}
}
+
+
+
+
static void
process_node (struct ods_reader *r)
{
static void
process_node (struct ods_reader *r)
{
@@
-298,6
+337,8
@@
process_node (struct ods_reader *r)
if (! xmlTextReaderIsEmptyElement (r->xtr))
r->state = STATE_ROW;
if (! xmlTextReaderIsEmptyElement (r->xtr))
r->state = STATE_ROW;
+
+ xmlFree (value);
}
else if (0 == xmlStrcasecmp (name, _xml("table:table")) &&
(XML_READER_TYPE_END_ELEMENT == r->node_type))
}
else if (0 == xmlStrcasecmp (name, _xml("table:table")) &&
(XML_READER_TYPE_END_ELEMENT == r->node_type))
@@
-471,7
+512,7
@@
get_sheet_count (struct zip_reader *zreader)
return -1;
mxtr = xmlReaderForIO ((xmlInputReadCallback) zip_member_read,
return -1;
mxtr = xmlReaderForIO ((xmlInputReadCallback) zip_member_read,
- (xmlInputCloseCallback)
zip_member_finish
,
+ (xmlInputCloseCallback)
NULL
,
meta, NULL, NULL, 0);
while (1 == xmlTextReaderRead (mxtr))
meta, NULL, NULL, 0);
while (1 == xmlTextReaderRead (mxtr))
@@
-521,11
+562,10
@@
init_reader (struct ods_reader *r, bool report_errors)
if ( content == NULL)
return false;
if ( content == NULL)
return false;
- zip_member_ref (content);
-
if (r->xtr)
xmlFreeTextReader (r->xtr);
if (r->xtr)
xmlFreeTextReader (r->xtr);
+ zip_member_ref (content);
xtr = xmlReaderForIO ((xmlInputReadCallback) zip_member_read,
(xmlInputCloseCallback) zip_member_finish,
content, NULL, NULL,
xtr = xmlReaderForIO ((xmlInputReadCallback) zip_member_read,
(xmlInputCloseCallback) zip_member_finish,
content, NULL, NULL,
@@
-570,6
+610,7
@@
ods_probe (const char *filename, bool report_errors)
r = xzalloc (sizeof *r);
r->zreader = zr;
r = xzalloc (sizeof *r);
r->zreader = zr;
+ r->ref_cnt = 1;
if (! init_reader (r, report_errors))
{
if (! init_reader (r, report_errors))
{
@@
-610,12
+651,12
@@
ods_make_reader (struct spreadsheet *spreadsheet,
assert (r);
r->read_names = opts->read_names;
ds_init_empty (&r->ods_errs);
assert (r);
r->read_names = opts->read_names;
ds_init_empty (&r->ods_errs);
-
+ ++r->ref_cnt;
if ( !init_reader (r, true))
goto error;
if ( !init_reader (r, true))
goto error;
- if (
opts->cell_range
)
+ if (
opts->cell_range
)
{
if ( ! convert_cell_ref (opts->cell_range,
&r->start_col, &r->start_row,
{
if ( ! convert_cell_ref (opts->cell_range,
&r->start_col, &r->start_row,
@@
-635,20
+676,11
@@
ods_make_reader (struct spreadsheet *spreadsheet,
}
r->state = STATE_INIT;
}
r->state = STATE_INIT;
- r->target_sheet_name =
BAD_CAST opts->sheet_name
;
+ r->target_sheet_name =
xmlStrdup (BAD_CAST opts->sheet_name)
;
r->target_sheet_index = opts->sheet_index;
r->row = r->col = 0;
r->target_sheet_index = opts->sheet_index;
r->row = r->col = 0;
-#if 0
- printf ("%s:%d %d,%d %d,%d\n", __FILE__, __LINE__,
- r->start_col,
- r->start_row,
- r->stop_col,
- r->stop_row);
-#endif
-
-
/* Advance to the start of the cells for the target sheet */
while ( ! reading_target_sheet (r)
|| r->state != STATE_ROW || r->row <= r->start_row )
/* Advance to the start of the cells for the target sheet */
while ( ! reading_target_sheet (r)
|| r->state != STATE_ROW || r->row <= r->start_row )
@@
-744,14
+776,6
@@
ods_make_reader (struct spreadsheet *spreadsheet,
if ( r->state == STATE_CELL_CONTENT &&
XML_READER_TYPE_TEXT == r->node_type)
{
if ( r->state == STATE_CELL_CONTENT &&
XML_READER_TYPE_TEXT == r->node_type)
{
-#if 0
- printf ("%s:%d Idx %d n_var_specs %d\n", __FILE__, __LINE__,
- idx, n_var_specs);
-
- printf ("%s:%d Idx %d r_col %d\n", __FILE__, __LINE__,
- idx, r->col);
-#endif
-
if (idx >= n_var_specs)
{
var_spec = xrealloc (var_spec, sizeof (*var_spec) * (idx + 1));
if (idx >= n_var_specs)
{
var_spec = xrealloc (var_spec, sizeof (*var_spec) * (idx + 1));
@@
-830,7
+854,6
@@
ods_make_reader (struct spreadsheet *spreadsheet,
break;
}
break;
}
- // zip_reader_destroy (zreader);
for ( i = 0 ; i < n_var_specs ; ++i )
{
for ( i = 0 ; i < n_var_specs ; ++i )
{
@@
-851,8
+874,7
@@
ods_make_reader (struct spreadsheet *spreadsheet,
error:
error:
- //zip_reader_destroy (zreader);
-
+#if 0
for ( i = 0 ; i < n_var_specs ; ++i )
{
free (var_spec[i].firstval.type);
for ( i = 0 ; i < n_var_specs ; ++i )
{
free (var_spec[i].firstval.type);
@@
-865,6
+887,7
@@
ods_make_reader (struct spreadsheet *spreadsheet,
dict_destroy (r->spreadsheet.dict);
r->spreadsheet.dict = NULL;
dict_destroy (r->spreadsheet.dict);
r->spreadsheet.dict = NULL;
+#endif
ods_file_casereader_destroy (NULL, r);
ods_file_casereader_destroy (NULL, r);
@@
-941,6
+964,8
@@
ods_file_casereader_read (struct casereader *reader UNUSED, void *r_)
continue;
if (r->stop_col != -1 && idx > r->stop_col - r->start_col )
break;
continue;
if (r->stop_col != -1 && idx > r->stop_col - r->start_col )
break;
+ if (idx >= dict_get_var_cnt (r->dict))
+ break;
var = dict_get_var (r->dict, idx);
convert_xml_to_value (c, var, xmv);
var = dict_get_var (r->dict, idx);
convert_xml_to_value (c, var, xmv);