Fixed dereference of free()'d memory.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 13 Mar 2012 07:49:59 -0400
changeset 1219 f479c6b1e7f7
parent 1218 643a34fc7c8f
child 1220 55246a31c9ca
Fixed dereference of free()'d memory. Thanks to Evgeny Podjachev for the fix!
src/archiver_dir.c
--- a/src/archiver_dir.c	Tue Mar 13 04:25:05 2012 -0400
+++ b/src/archiver_dir.c	Tue Mar 13 07:49:59 2012 -0400
@@ -64,20 +64,21 @@
     if (fileExists == NULL)
         fileExists = &existtmp;
 
-    *fileExists = 0;
-
     BAIL_IF_MACRO(f == NULL, NULL, NULL);
 
     io = __PHYSFS_createNativeIo(f, mode);
-    allocator.Free(f);
     if (io == NULL)
     {
         PHYSFS_Stat statbuf;  /* !!! FIXME: this changes the error message. */
         __PHYSFS_platformStat(f, fileExists, &statbuf);
-        return NULL;
     } /* if */
+    else
+    {
+        *fileExists = 1;
+    } /* else */
 
-    *fileExists = 1;
+    allocator.Free(f);
+
     return io;
 } /* doOpen */