Fixed resource leak when failing to mount a file that isn't an archive.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 19 Aug 2014 02:28:13 -0400
changeset 1353 5ef6aca28421
parent 1351 ea662d0cbcf0
child 1354 3e80839670da
Fixed resource leak when failing to mount a file that isn't an archive.
src/physfs.c
--- a/src/physfs.c	Thu Aug 14 21:33:24 2014 -0400
+++ b/src/physfs.c	Tue Aug 19 02:28:13 2014 -0400
@@ -828,6 +828,7 @@
     DirHandle *retval = NULL;
     const PHYSFS_Archiver **i;
     const char *ext;
+    int created_io = 0;
 
     assert((io != NULL) || (d != NULL));
 
@@ -841,6 +842,7 @@
 
         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 @@
             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 */