Fixed some memory leaks
[pspp] / src / data / ods-reader.c
index cbd7feaa170d8f51d4245f879c9b526a4594be20..4efb2a50076ce886142cc1a70679756fd7f6f4f3 100644 (file)
@@ -113,6 +113,13 @@ struct state_data
   int col_span;
 };
 
+static void
+state_data_destroy (struct state_data *sd)
+{
+  xmlFree (sd->current_sheet_name);
+  xmlFreeTextReader (sd->xtr);
+}
+
 struct ods_reader
 {
   struct spreadsheet spreadsheet;
@@ -144,23 +151,23 @@ struct ods_reader
 void
 ods_destroy (struct spreadsheet *s)
 {
-#if 0
   struct ods_reader *r = (struct ods_reader *) s;
 
   if (--r->ref_cnt == 0)
     {
       int i;
 
+      state_data_destroy (&r->foo);
       for (i = 0; i < r->n_allocated_sheets; ++i)
        {
          xmlFree (r->sheets[i].name);
        }
-
+       
       zip_reader_destroy (r->zreader);
       free (r->sheets);
+       
       free (r);
     }
-#endif
 }
 
 
@@ -239,14 +246,11 @@ ods_get_sheet_range (struct spreadsheet *s, int n)
 static void
 ods_file_casereader_destroy (struct casereader *reader UNUSED, void *r_)
 {
-#if 0
   struct ods_reader *r = r_;
   if ( r == NULL)
     return ;
 
-  if (r->xtr)
-    xmlFreeTextReader (r->xtr);
-  r->xtr = NULL;
+  state_data_destroy (&r->rsd);
 
   if ( ! ds_is_empty (&r->ods_errs))
     msg (ME, "%s", ds_cstr (&r->ods_errs));
@@ -258,11 +262,9 @@ ods_file_casereader_destroy (struct casereader *reader UNUSED, void *r_)
 
   caseproto_unref (r->proto);
 
-  xmlFree (r->current_sheet_name);
   xmlFree (r->target_sheet_name);
 
   ods_destroy (&r->spreadsheet);
-#endif
 }
 
 
@@ -562,9 +564,8 @@ init_reader (struct ods_reader *r, bool report_errors)
   if ( content == NULL)
     return NULL;
 
-  zip_member_ref (content);
   xtr = xmlReaderForIO ((xmlInputReadCallback) zip_member_read,
-                       (xmlInputCloseCallback) zip_member_finish,
+                       (xmlInputCloseCallback) NULL,
                        content,   NULL, NULL,
                        report_errors ? 0 : (XML_PARSE_NOERROR | XML_PARSE_NOWARNING) );
 
@@ -905,8 +906,6 @@ static struct ccase *
 ods_file_casereader_read (struct casereader *reader UNUSED, void *r_)
 {
   struct ccase *c = NULL;
-  xmlChar *val_string = NULL;
-  xmlChar *type = NULL;
   struct ods_reader *r = r_;
 
   if (!r->used_first_case)
@@ -936,6 +935,9 @@ ods_file_casereader_read (struct casereader *reader UNUSED, void *r_)
   c = case_create (r->proto);
   case_set_missing (c);
   
+  xmlChar *val_string = NULL;
+  xmlChar *type = NULL;
+
   while (1 == xmlTextReaderRead (r->rsd.xtr))
     {
       process_node (r, &r->rsd);