[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

libdvdread: Patch OK?



Does this patch look OK, or is it totally wrong? Build tested so far.


--- libdvdread-4.1.4-1219/src/dvd_reader.c	2010-07-31 02:10:28.000000000 +0200
+++ libdvdread-4.1.4-1219.modified/src/dvd_reader.c	2011-09-04 23:38:43.000000000 +0200
@@ -424,21 +424,18 @@
         if( chdir( path_copy ) == -1 ) {
           goto DVDOpen_error;
         }
-        new_path = malloc(PATH_MAX+1);
-        if(!new_path) {
-          goto DVDOpen_error;
-        }
-        if( getcwd( new_path, PATH_MAX ) == NULL ) {
+        if( getcwd( new_path, NULL ) == NULL ) {
           goto DVDOpen_error;
         }
         retval = fchdir( cdir );
         close( cdir );
         cdir = -1;
         if( retval == -1 ) {
+          free( new_path );
           goto DVDOpen_error;
         }
         path_copy = new_path;
-        new_path = NULL;
+        free( new_path );
       }
     }
 #endif
@@ -635,9 +632,15 @@
 
   while( ( ent = readdir( dir ) ) != NULL ) {
     if( !strcasecmp( ent->d_name, file ) ) {
+#ifdef __GNU__
+      asprintf( &filename, "%s%s%s", path,
+               ( ( path[ strlen( path ) - 1 ] == '/' ) ? "" : "/" ),
+               ent->d_name );
+#else
       sprintf( filename, "%s%s%s", path,
                ( ( path[ strlen( path ) - 1 ] == '/' ) ? "" : "/" ),
                ent->d_name );
+#endif
       closedir(dir);
       return 0;
     }
@@ -648,7 +651,11 @@
 
 static int findDVDFile( dvd_reader_t *dvd, const char *file, char *filename )
 {
+#ifdef __GNU__
+  char *video_path = NULL;
+#else
   char video_path[ PATH_MAX + 1 ];
+#endif
   const char *nodirfile;
   int ret;
 
@@ -662,18 +669,30 @@
   ret = findDirFile( dvd->path_root, nodirfile, filename );
   if( ret < 0 ) {
     /* Try also with adding the path, just in case. */
+#ifdef __GNU__
+    asprintf( &video_path, "%s/VIDEO_TS/", dvd->path_root );
+#else
     sprintf( video_path, "%s/VIDEO_TS/", dvd->path_root );
+#endif
     ret = findDirFile( video_path, nodirfile, filename );
     if( ret < 0 ) {
       /* Try with the path, but in lower case. */
+#ifdef __GNU__
+      asprintf( video_path, "%s/video_ts/", dvd->path_root );
+#else
       sprintf( video_path, "%s/video_ts/", dvd->path_root );
+#endif
       ret = findDirFile( video_path, nodirfile, filename );
       if( ret < 0 ) {
+#ifdef __GNU__
+	free( video_path );
+#endif
         return 0;
       }
     }
   }
 
+  free( video_path );
   return 1;
 }
 
@@ -682,7 +701,11 @@
  */
 static dvd_file_t *DVDOpenFilePath( dvd_reader_t *dvd, char *filename )
 {
+#ifdef __GNU__
+  char *full_path = NULL;
+#else
   char full_path[ PATH_MAX + 1 ];
+#endif
   dvd_file_t *dvd_file;
   struct stat fileinfo;
   dvd_input_t dev;
@@ -690,12 +713,18 @@
   /* Get the full path of the file. */
   if( !findDVDFile( dvd, filename, full_path ) ) {
     fprintf( stderr, "libdvdnav:DVDOpenFilePath:findDVDFile %s failed\n", filename );
+#ifdef __GNU__
+    free( full_path );
+#endif
     return NULL;
   }
 
   dev = dvdinput_open( full_path );
   if( !dev ) {
     fprintf( stderr, "libdvdnav:DVDOpenFilePath:dvdinput_open %s failed\n", full_path );
+#ifdef __GNU__
+    free( full_path );
+#endif
     return NULL;
   }
 
@@ -703,6 +732,9 @@
   if( !dvd_file ) {
     fprintf( stderr, "libdvdnav:DVDOpenFilePath:dvd_file malloc failed\n" );
     dvdinput_close(dev);
+#ifdef __GNU__
+    free( full_path );
+#endif
     return NULL;
   }
   dvd_file->dvd = dvd;
@@ -715,12 +747,18 @@
   if( stat( full_path, &fileinfo ) < 0 ) {
     fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
     free( dvd_file );
+#ifdef __GNU__
+    free( full_path );
+#endif
     return NULL;
   }
   dvd_file->title_sizes[ 0 ] = fileinfo.st_size / DVD_VIDEO_LB_LEN;
   dvd_file->title_devs[ 0 ] = dev;
   dvd_file->filesize = dvd_file->title_sizes[ 0 ];
 
+#ifdef __GNU__
+  free( full_path );
+#endif
   return dvd_file;
 }
 
@@ -776,7 +814,11 @@
 static dvd_file_t *DVDOpenVOBPath( dvd_reader_t *dvd, int title, int menu )
 {
   char filename[ MAX_UDF_FILE_NAME_LEN ];
+#ifdef __GNU__
+  char *full_path = NULL;
+#else
   char full_path[ PATH_MAX + 1 ];
+#endif
   struct stat fileinfo;
   dvd_file_t *dvd_file;
   int i;
@@ -966,7 +1008,11 @@
                                int menu, dvd_stat_t *statbuf )
 {
   char filename[ MAX_UDF_FILE_NAME_LEN ];
+#ifdef __GNU__
+  char *full_path = NULL;
+#else
   char full_path[ PATH_MAX + 1 ];
+#endif
   struct stat fileinfo;
   off_t tot_size;
   off_t parts_size[ 9 ];
@@ -1021,7 +1067,11 @@
                  dvd_read_domain_t domain, dvd_stat_t *statbuf )
 {
   char filename[ MAX_UDF_FILE_NAME_LEN ];
+#ifdef __GNU__
+  char *full_path = NULL;
+#else
   char full_path[ PATH_MAX + 1 ];
+#endif
   struct stat fileinfo;
   uint32_t size;
 
@@ -1054,9 +1104,12 @@
 
     break;
   case DVD_READ_TITLE_VOBS:
-    if( titlenum == 0 )
+    if( titlenum == 0 ) {
+#ifdef __GNU__
+      free( full_path );
+#endif
       return -1;
-
+    }
     if( dvd->isImageFile )
       return DVDFileStatVOBUDF( dvd, titlenum, 0, statbuf );
     else
@@ -1066,6 +1119,9 @@
   default:
     fprintf( stderr, "libdvdread: Invalid domain for file stat.\n" );
     errno = EINVAL;
+#ifdef __GNU__
+    free( full_path );
+#endif
     return -1;
   }
 
@@ -1074,6 +1130,9 @@
       statbuf->size = size;
       statbuf->nr_parts = 1;
       statbuf->parts_size[ 0 ] = size;
+#ifdef __GNU__
+      free( full_path );
+#endif
       return 0;
     }
   } else {
@@ -1084,10 +1143,16 @@
         statbuf->size = fileinfo.st_size;
         statbuf->nr_parts = 1;
         statbuf->parts_size[ 0 ] = statbuf->size;
+#ifdef __GNU__
+        free( full_path );
+#endif
         return 0;
       }
     }
   }
+#ifdef __GNU__
+  free( full_path );
+#endif
   return -1;
 }
 

Reply to: