From 729fd0f2e918a3a782710ec7ec525867eaa1c64e Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 8 Mar 2013 16:10:14 +0100 Subject: [PATCH] Ref count the gnumeric reader --- src/data/gnumeric-reader.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/data/gnumeric-reader.c b/src/data/gnumeric-reader.c index 7dbc63a9d6..71dc4a1be7 100644 --- a/src/data/gnumeric-reader.c +++ b/src/data/gnumeric-reader.c @@ -104,6 +104,7 @@ struct sheet_detail struct gnumeric_reader { struct spreadsheet spreadsheet; + int ref_cnt; /* The libxml reader for this instance */ xmlTextReaderPtr xtr; @@ -138,16 +139,20 @@ void gnumeric_destroy (struct spreadsheet *s) { struct gnumeric_reader *r = s; - int i; - for (i = 0; i < s->n_sheets; ++i) + if (0 == --r->ref_cnt) { - xmlFree (r->sheets[i].name); - } + int i; + + for (i = 0; i < s->n_sheets; ++i) + { + xmlFree (r->sheets[i].name); + } - free (r->sheets); + free (r->sheets); - free (r); + free (r); + } } @@ -496,6 +501,7 @@ gnumeric_reopen (struct gnumeric_reader *r, const char *filename, bool show_erro r->row = r->col = -1; r->state = STATE_PRE_INIT; r->xtr = xtr; + r->ref_cnt++; /* Advance to the start of the workbook. This gives us some confidence that we are actually dealing with a gnumeric @@ -565,6 +571,8 @@ gnumeric_make_reader (struct spreadsheet *spreadsheet, if (r->row != -1) r = gnumeric_reopen (r, NULL, true); + + if ( opts->cell_range ) { if ( ! convert_cell_ref (opts->cell_range, -- 2.30.2