changeset 12:056f5573a7dc src

moved various pieces of duplicated code to free_ptl_mait(); patch by Erik Hovland org
author nicodvb
date Wed, 16 Jul 2008 07:46:33 +0000
parents 5b63b7151e60
children 4e610984cc3f
files ifo_read.c
diffstat 1 files changed, 12 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/ifo_read.c	Sun Jul 13 12:27:17 2008 +0000
+++ b/ifo_read.c	Wed Jul 16 07:46:33 2008 +0000
@@ -276,6 +276,15 @@
   pt->title_or_time_play              = dvdread_getbits(&state, 1);
 }
 
+static void free_ptl_mait(ptl_mait_t* ptl_mait, int num_entries) {
+  int i;
+  for (i = 0; i < num_entries; i++)
+    free(ptl_mait->countries[i].pf_ptl_mai);
+
+  free(ptl_mait->countries);
+  free(ptl_mait);
+}
+
 ifo_handle_t *ifoOpen(dvd_reader_t *dvd, int title) {
   ifo_handle_t *ifofile;
 
@@ -1299,21 +1308,13 @@
     info_length = (ptl_mait->nr_of_vtss + 1) * sizeof(pf_level_t);
     pf_temp = (uint16_t *)malloc(info_length);
     if(!pf_temp) {
-      for(j = 0; j < i ; j++) {
-         free(ptl_mait->countries[j].pf_ptl_mai);
-      }
-      free(ptl_mait->countries);
-      free(ptl_mait);
+      free_ptl_mait(ptl_mait, i);
       return 0;
     }
     if(!(DVDReadBytes(ifofile->file, pf_temp, info_length))) {
        fprintf(stderr, "libdvdread: Unable to read PTL_MAIT table.\n");
        free(pf_temp);
-       for(j = 0; j < i ; j++) {
-	  free(ptl_mait->countries[j].pf_ptl_mai);
-       }
-       free(ptl_mait->countries);
-       free(ptl_mait);
+       free_ptl_mait(ptl_mait, i);
        return 0;
     }
     for (j = 0; j < ((ptl_mait->nr_of_vtss + 1) * 8); j++) {
@@ -1322,11 +1323,7 @@
     ptl_mait->countries[i].pf_ptl_mai = (pf_level_t *)malloc(info_length);
     if(!ptl_mait->countries[i].pf_ptl_mai) {
       free(pf_temp);
-      for(j = 0; j < i ; j++) {
-	free(ptl_mait->countries[j].pf_ptl_mai);
-      }
-      free(ptl_mait->countries);
-      free(ptl_mait);
+      free_ptl_mait(ptl_mait, i);
       return 0;
     }
     { /* Transpose the array so we can use C indexing. */