More FIXME cleanup.
authorRyan C. Gordon <icculus@icculus.org>
Sat, 24 Mar 2012 00:49:34 -0400
changeset 1269 8a7e381fbc29
parent 1268 ca011e15e377
child 1270 f8d3f58561b1
More FIXME cleanup.
docs/TODO.txt
src/archiver_zip.c
--- a/docs/TODO.txt	Sat Mar 24 00:32:22 2012 -0400
+++ b/docs/TODO.txt	Sat Mar 24 00:49:34 2012 -0400
@@ -37,7 +37,6 @@
   important, since streaming archives aren't of much value to games (which
   is why zipfiles are king: random access), but it could have uses for, say,
   an installer/updater.
-- Reduce malloc() pressure all over the place. We fragment memory like mad.
 - profile string list interpolation.
 - We have two different ways to find dir entries in zip.c.
 - Do symlinks in zip archiver work when they point to dirs?
--- a/src/archiver_zip.c	Sat Mar 24 00:32:22 2012 -0400
+++ b/src/archiver_zip.c	Sat Mar 24 00:49:34 2012 -0400
@@ -333,28 +333,27 @@
     ZIPfileinfo *origfinfo = (ZIPfileinfo *) io->opaque;
     PHYSFS_Io *retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io));
     ZIPfileinfo *finfo = (ZIPfileinfo *) allocator.Malloc(sizeof (ZIPfileinfo));
-    GOTO_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, ZIP_duplicate_failed);
-    GOTO_IF_MACRO(!finfo, PHYSFS_ERR_OUT_OF_MEMORY, ZIP_duplicate_failed);
+    GOTO_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, failed);
+    GOTO_IF_MACRO(!finfo, PHYSFS_ERR_OUT_OF_MEMORY, failed);
     memset(finfo, '\0', sizeof (*finfo));
 
     finfo->entry = origfinfo->entry;
     finfo->io = zip_get_io(origfinfo->io, NULL, finfo->entry);
-    GOTO_IF_MACRO(!finfo->io, ERRPASS, ZIP_duplicate_failed);
+    GOTO_IF_MACRO(!finfo->io, ERRPASS, failed);
 
     if (finfo->entry->compression_method != COMPMETH_NONE)
     {
         finfo->buffer = (PHYSFS_uint8 *) allocator.Malloc(ZIP_READBUFSIZE);
-        if (!finfo->buffer)
-            GOTO_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, ZIP_duplicate_failed);
-        else if (zlib_err(inflateInit2(&finfo->stream, -MAX_WBITS)) != Z_OK)
-            goto ZIP_duplicate_failed;
+        GOTO_IF_MACRO(!finfo->buffer, PHYSFS_ERR_OUT_OF_MEMORY, failed);
+        if (zlib_err(inflateInit2(&finfo->stream, -MAX_WBITS)) != Z_OK)
+            goto failed;
     } /* if */
 
     memcpy(retval, io, sizeof (PHYSFS_Io));
     retval->opaque = finfo;
     return retval;
 
-ZIP_duplicate_failed:
+failed:
     if (finfo != NULL)
     {
         if (finfo->io != NULL)
@@ -671,8 +670,7 @@
  * Look for the entry named by (path). If it exists, resolve it, and return
  *  a pointer to that entry. If it's another symlink, keep resolving until you
  *  hit a real file and then return a pointer to the final non-symlink entry.
- *  If there's a problem, return NULL. (path) is always free()'d by this
- *  function.
+ *  If there's a problem, return NULL.
  */
 static ZIPentry *zip_follow_symlink(PHYSFS_Io *io, ZIPinfo *info, char *path)
 {
@@ -691,15 +689,14 @@
         } /* else */
     } /* if */
 
-    allocator.Free(path);
     return entry;
 } /* zip_follow_symlink */
 
 
 static int zip_resolve_symlink(PHYSFS_Io *io, ZIPinfo *info, ZIPentry *entry)
 {
-    char *path;
     const PHYSFS_uint32 size = entry->uncompressed_size;
+    char *path = NULL;
     int rc = 0;
 
     /*
@@ -710,8 +707,8 @@
 
     BAIL_IF_MACRO(!io->seek(io, entry->offset), ERRPASS, 0);
 
-    path = (char *) allocator.Malloc(size + 1);
-    BAIL_IF_MACRO(path == NULL, PHYSFS_ERR_OUT_OF_MEMORY, 0);
+    path = (char *) __PHYSFS_smallAlloc(size + 1);
+    BAIL_IF_MACRO(!path, PHYSFS_ERR_OUT_OF_MEMORY, 0);
     
     if (entry->compression_method == COMPMETH_NONE)
         rc = __PHYSFS_readAll(io, path, size);
@@ -743,15 +740,15 @@
         } /* if */
     } /* else */
 
-    if (!rc)
-        allocator.Free(path);
-    else
+    if (rc)
     {
         path[entry->uncompressed_size] = '\0';    /* null-terminate it. */
         zip_convert_dos_path(entry, path);
         entry->symlink = zip_follow_symlink(io, info, path);
     } /* else */
 
+    __PHYSFS_smallFree(path);
+
     return (entry->symlink != NULL);
 } /* zip_resolve_symlink */