Alexandre Julliard : cabinet: Don't allocate a huge buffer on the stack.

Alexandre Julliard julliard at winehq.org
Thu Dec 11 07:50:45 CST 2008


Module: wine
Branch: master
Commit: 16fb8fd843cbf23f74768aee86e3c808e92b6ba0
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=16fb8fd843cbf23f74768aee86e3c808e92b6ba0

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu Dec 11 12:24:33 2008 +0100

cabinet: Don't allocate a huge buffer on the stack.

---

 dlls/cabinet/fdi.c |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/dlls/cabinet/fdi.c b/dlls/cabinet/fdi.c
index 09d0fe7..4923404 100644
--- a/dlls/cabinet/fdi.c
+++ b/dlls/cabinet/fdi.c
@@ -2279,8 +2279,7 @@ static void free_decompression_temps(HFDI hfdi, struct fdi_folder *fol,
 }
 
 static void free_decompression_mem(HFDI hfdi, struct fdi_folder *fol,
-  fdi_decomp_state *decomp_state, fdi_decomp_state *sentinel_decomp_state,
-  struct fdi_file *file)
+  fdi_decomp_state *decomp_state, struct fdi_file *file)
 {
   while (decomp_state) {
     fdi_decomp_state *prev_fds;
@@ -2306,8 +2305,7 @@ static void free_decompression_mem(HFDI hfdi, struct fdi_folder *fol,
     }
     prev_fds = decomp_state;
     decomp_state = CAB(next);
-    if (prev_fds != sentinel_decomp_state)
-      PFDI_FREE(hfdi, prev_fds);
+    PFDI_FREE(hfdi, prev_fds);
   }
 }
 
@@ -2495,8 +2493,7 @@ BOOL __cdecl FDICopy(
   cab_UBYTE         buf[64];
   struct fdi_folder *fol = NULL, *linkfol = NULL; 
   struct fdi_file   *file = NULL, *linkfile = NULL;
-  fdi_decomp_state _decomp_state;
-  fdi_decomp_state *decomp_state = &_decomp_state;
+  fdi_decomp_state *decomp_state;
 
   TRACE("(hfdi == ^%p, pszCabinet == ^%p, pszCabPath == ^%p, flags == %0d, "
         "pfnfdin == ^%p, pfnfdid == ^%p, pvUser == ^%p)\n",
@@ -2507,6 +2504,11 @@ BOOL __cdecl FDICopy(
     return FALSE;
   }
 
+  if (!(decomp_state = PFDI_ALLOC(hfdi, sizeof(fdi_decomp_state))))
+  {
+      SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+      return FALSE;
+  }
   ZeroMemory(decomp_state, sizeof(fdi_decomp_state));
 
   pathlen = (pszCabPath) ? strlen(pszCabPath) : 0;
@@ -2893,7 +2895,7 @@ BOOL __cdecl FDICopy(
   }
 
   free_decompression_temps(hfdi, fol, decomp_state);
-  free_decompression_mem(hfdi, fol, decomp_state, &_decomp_state, file);
+  free_decompression_mem(hfdi, fol, decomp_state, file);
  
   return TRUE;
 
@@ -2903,7 +2905,7 @@ BOOL __cdecl FDICopy(
 
   if (filehf) PFDI_CLOSE(hfdi, filehf);
 
-  free_decompression_mem(hfdi, fol, decomp_state, &_decomp_state, file);
+  free_decompression_mem(hfdi, fol, decomp_state, file);
 
   return FALSE;
 }




More information about the wine-cvs mailing list