From 53ef674270733f7bfb7287804b0844d8acc99f9d Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 19 Aug 2014 02:28:13 -0400 Subject: [PATCH] Fixed resource leak when failing to mount a file that isn't an archive. --- src/physfs.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/physfs.c b/src/physfs.c index a27f3d0c..2a6bb496 100644 --- a/src/physfs.c +++ b/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 */