Преглед на файлове

Fixed resource leak when failing to mount a file that isn't an archive.

Ryan C. Gordon преди 11 години
родител
ревизия
53ef674270
променени са 1 файла, в които са добавени 5 реда и са изтрити 0 реда
  1. 5 0
      src/physfs.c

+ 5 - 0
src/physfs.c

@@ -828,6 +828,7 @@ static DirHandle *openDirectory(PHYSFS_Io *io, const char *d, int forWriting)
     DirHandle *retval = NULL;
     const PHYSFS_Archiver **i;
     const char *ext;
+    int created_io = 0;
 
     assert((io != NULL) || (d != NULL));
 
@@ -841,6 +842,7 @@ static DirHandle *openDirectory(PHYSFS_Io *io, const char *d, int forWriting)
 
         io = __PHYSFS_createNativeIo(d, forWriting ? 'w' : 'r');
         BAIL_IF_MACRO(!io, ERRPASS, 0);
+        created_io = 1;
     } /* if */
 
     ext = find_filename_extension(d);
@@ -867,6 +869,9 @@ static DirHandle *openDirectory(PHYSFS_Io *io, const char *d, int forWriting)
             retval = tryOpenDir(io, *i, d, forWriting);
     } /* else */
 
+    if ((!retval) && (created_io))
+        io->destroy(io);
+
     BAIL_IF_MACRO(!retval, PHYSFS_ERR_UNSUPPORTED, NULL);
     return retval;
 } /* openDirectory */