Hans Leidekker : msi: Use CRT allocation functions.

Alexandre Julliard julliard at winehq.org
Tue Feb 1 15:21:35 CST 2022


Module: wine
Branch: master
Commit: 0d5f28457e8eced81677509f5129a20f10df526c
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=0d5f28457e8eced81677509f5129a20f10df526c

Author: Hans Leidekker <hans at codeweavers.com>
Date:   Tue Feb  1 14:57:01 2022 +0100

msi: Use CRT allocation functions.

Signed-off-by: Hans Leidekker <hans at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/msi/custom.c  |  5 ++---
 dlls/msi/handle.c  |  6 +++---
 dlls/msi/install.c | 17 ++++++++---------
 dlls/msi/msipriv.h | 16 +++++-----------
 dlls/msi/package.c | 15 +++++++--------
 dlls/msi/streams.c |  3 ++-
 dlls/msi/string.c  | 10 ++++------
 dlls/msi/where.c   |  3 ++-
 8 files changed, 33 insertions(+), 42 deletions(-)

diff --git a/dlls/msi/custom.c b/dlls/msi/custom.c
index ee4f59b5faa..94c159c6a2a 100644
--- a/dlls/msi/custom.c
+++ b/dlls/msi/custom.c
@@ -36,7 +36,6 @@
 #include "msipriv.h"
 #include "winemsi.h"
 #include "wine/asm.h"
-#include "wine/heap.h"
 #include "wine/debug.h"
 #include "wine/exception.h"
 
@@ -68,12 +67,12 @@ static struct list msi_pending_custom_actions = LIST_INIT( msi_pending_custom_ac
 
 void  __RPC_FAR * __RPC_USER MIDL_user_allocate(SIZE_T len)
 {
-    return heap_alloc(len);
+    return malloc(len);
 }
 
 void __RPC_USER MIDL_user_free(void __RPC_FAR * ptr)
 {
-    heap_free(ptr);
+    free(ptr);
 }
 
 LONG WINAPI rpc_filter(EXCEPTION_POINTERS *eptr)
diff --git a/dlls/msi/handle.c b/dlls/msi/handle.c
index 0881833ff68..26d8e7d7f85 100644
--- a/dlls/msi/handle.c
+++ b/dlls/msi/handle.c
@@ -92,13 +92,13 @@ static MSIHANDLE alloc_handle_table_entry(void)
         if (msihandletable_size == 0)
         {
             newsize = 256;
-            p = msi_alloc_zero(newsize*sizeof(msi_handle_info));
+            p = msi_alloc_zero(newsize * sizeof(*p));
         }
         else
         {
             newsize = msihandletable_size * 2;
-            p = msi_realloc_zero(msihandletable,
-                            newsize*sizeof(msi_handle_info));
+            p = msi_realloc(msihandletable, newsize * sizeof(*p));
+            if (p) memset(p + msihandletable_size, 0, (newsize - msihandletable_size) * sizeof(*p));
         }
         if (!p)
             return 0;
diff --git a/dlls/msi/install.c b/dlls/msi/install.c
index a3bfb53cfff..4d909b67682 100644
--- a/dlls/msi/install.c
+++ b/dlls/msi/install.c
@@ -34,7 +34,6 @@
 
 #include "msipriv.h"
 #include "winemsi.h"
-#include "wine/heap.h"
 #include "wine/debug.h"
 #include "wine/exception.h"
 
@@ -273,7 +272,7 @@ UINT WINAPI MsiGetTargetPathA(MSIHANDLE hinst, const char *folder, char *buf, DW
 
         if (!(remote = msi_get_remote(hinst)))
         {
-            heap_free(folderW);
+            free(folderW);
             return ERROR_INVALID_HANDLE;
         }
 
@@ -291,7 +290,7 @@ UINT WINAPI MsiGetTargetPathA(MSIHANDLE hinst, const char *folder, char *buf, DW
             r = msi_strncpyWtoA(path, -1, buf, sz, TRUE);
 
         midl_user_free(path);
-        heap_free(folderW);
+        free(folderW);
         return r;
     }
 
@@ -301,7 +300,7 @@ UINT WINAPI MsiGetTargetPathA(MSIHANDLE hinst, const char *folder, char *buf, DW
     else
         r = ERROR_DIRECTORY;
 
-    heap_free(folderW);
+    free(folderW);
     msiobj_release(&package->hdr);
     return r;
 }
@@ -429,7 +428,7 @@ UINT WINAPI MsiGetSourcePathA(MSIHANDLE hinst, const char *folder, char *buf, DW
 
         if (!(remote = msi_get_remote(hinst)))
         {
-            heap_free(folderW);
+            free(folderW);
             return ERROR_INVALID_HANDLE;
         }
 
@@ -447,7 +446,7 @@ UINT WINAPI MsiGetSourcePathA(MSIHANDLE hinst, const char *folder, char *buf, DW
             r = msi_strncpyWtoA(path, -1, buf, sz, TRUE);
 
         midl_user_free(path);
-        heap_free(folderW);
+        free(folderW);
         return r;
     }
 
@@ -457,8 +456,8 @@ UINT WINAPI MsiGetSourcePathA(MSIHANDLE hinst, const char *folder, char *buf, DW
     else
         r = ERROR_DIRECTORY;
 
-    heap_free(path);
-    heap_free(folderW);
+    free(path);
+    free(folderW);
     msiobj_release(&package->hdr);
     return r;
 }
@@ -509,7 +508,7 @@ UINT WINAPI MsiGetSourcePathW(MSIHANDLE hinst, const WCHAR *folder, WCHAR *buf,
     else
         r = ERROR_DIRECTORY;
 
-    heap_free(path);
+    free(path);
     msiobj_release(&package->hdr);
     return r;
 }
diff --git a/dlls/msi/msipriv.h b/dlls/msi/msipriv.h
index 15130446b04..b5838bad6fe 100644
--- a/dlls/msi/msipriv.h
+++ b/dlls/msi/msipriv.h
@@ -1141,30 +1141,24 @@ extern void msi_ui_progress(MSIPACKAGE *, int, int, int, int) DECLSPEC_HIDDEN;
 static void *msi_alloc( size_t len ) __WINE_ALLOC_SIZE(1);
 static inline void *msi_alloc( size_t len )
 {
-    return HeapAlloc( GetProcessHeap(), 0, len );
+    return malloc( len );
 }
 
 static void *msi_alloc_zero( size_t len ) __WINE_ALLOC_SIZE(1);
 static inline void *msi_alloc_zero( size_t len )
 {
-    return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, len );
+    return calloc( 1, len );
 }
 
 static void *msi_realloc( void *mem, size_t len ) __WINE_ALLOC_SIZE(2);
 static inline void *msi_realloc( void *mem, size_t len )
 {
-    return HeapReAlloc( GetProcessHeap(), 0, mem, len );
+    return realloc( mem, len );
 }
 
-static void *msi_realloc_zero( void *mem, size_t len ) __WINE_ALLOC_SIZE(2);
-static inline void *msi_realloc_zero( void *mem, size_t len )
+static inline void msi_free( void *mem )
 {
-    return HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len );
-}
-
-static inline BOOL msi_free( void *mem )
-{
-    return HeapFree( GetProcessHeap(), 0, mem );
+    free( mem );
 }
 
 static inline char *strdupWtoA( LPCWSTR str )
diff --git a/dlls/msi/package.c b/dlls/msi/package.c
index 7488c095080..349d7c0ffa3 100644
--- a/dlls/msi/package.c
+++ b/dlls/msi/package.c
@@ -43,7 +43,6 @@
 #include "msidefs.h"
 #include "sddl.h"
 
-#include "wine/heap.h"
 #include "wine/debug.h"
 #include "wine/exception.h"
 
@@ -2272,7 +2271,7 @@ UINT WINAPI MsiGetPropertyA(MSIHANDLE hinst, const char *name, char *buf, DWORD
 
         if (!(remote = msi_get_remote(hinst)))
         {
-            heap_free(nameW);
+            free(nameW);
             return ERROR_INVALID_HANDLE;
         }
 
@@ -2286,13 +2285,13 @@ UINT WINAPI MsiGetPropertyA(MSIHANDLE hinst, const char *name, char *buf, DWORD
         }
         __ENDTRY
 
-        heap_free(nameW);
+        free(nameW);
 
         if (!r)
         {
             /* String might contain embedded nulls.
              * Native returns the correct size but truncates the string. */
-            tmp = heap_alloc_zero((len + 1) * sizeof(WCHAR));
+            tmp = calloc(1, (len + 1) * sizeof(WCHAR));
             if (!tmp)
             {
                 midl_user_free(value);
@@ -2302,7 +2301,7 @@ UINT WINAPI MsiGetPropertyA(MSIHANDLE hinst, const char *name, char *buf, DWORD
 
             r = msi_strncpyWtoA(tmp, len, buf, sz, TRUE);
 
-            heap_free(tmp);
+            free(tmp);
         }
         midl_user_free(value);
         return r;
@@ -2314,7 +2313,7 @@ UINT WINAPI MsiGetPropertyA(MSIHANDLE hinst, const char *name, char *buf, DWORD
 
     r = msi_strncpyWtoA(value, len, buf, sz, FALSE);
 
-    heap_free(nameW);
+    free(nameW);
     if (row) msiobj_release(&row->hdr);
     msiobj_release(&package->hdr);
     return r;
@@ -2355,7 +2354,7 @@ UINT WINAPI MsiGetPropertyW(MSIHANDLE hinst, const WCHAR *name, WCHAR *buf, DWOR
         {
             /* String might contain embedded nulls.
              * Native returns the correct size but truncates the string. */
-            tmp = heap_alloc_zero((len + 1) * sizeof(WCHAR));
+            tmp = calloc(1, (len + 1) * sizeof(WCHAR));
             if (!tmp)
             {
                 midl_user_free(value);
@@ -2365,7 +2364,7 @@ UINT WINAPI MsiGetPropertyW(MSIHANDLE hinst, const WCHAR *name, WCHAR *buf, DWOR
 
             r = msi_strncpyW(tmp, len, buf, sz);
 
-            heap_free(tmp);
+            free(tmp);
         }
         midl_user_free(value);
         return r;
diff --git a/dlls/msi/streams.c b/dlls/msi/streams.c
index 1ef99c2ab05..8f6986039a9 100644
--- a/dlls/msi/streams.c
+++ b/dlls/msi/streams.c
@@ -57,7 +57,8 @@ static BOOL streams_resize_table( MSIDATABASE *db, UINT size )
     {
         MSISTREAM *tmp;
         UINT new_size = db->num_streams_allocated * 2;
-        if (!(tmp = msi_realloc_zero( db->streams, new_size * sizeof(MSISTREAM) ))) return FALSE;
+        if (!(tmp = msi_realloc( db->streams, new_size * sizeof(*tmp) ))) return FALSE;
+        memset( tmp + db->num_streams_allocated, 0, (new_size - db->num_streams_allocated) * sizeof(*tmp) );
         db->streams = tmp;
         db->num_streams_allocated = new_size;
     }
diff --git a/dlls/msi/string.c b/dlls/msi/string.c
index 0e250ff4527..fb0134810b9 100644
--- a/dlls/msi/string.c
+++ b/dlls/msi/string.c
@@ -139,13 +139,11 @@ static int st_find_free_entry( string_table *st )
             return i;
 
     /* dynamically resize */
-    sz = st->maxcount + 1 + st->maxcount/2;
-    p = msi_realloc_zero( st->strings, sz * sizeof(struct msistring) );
-    if( !p )
-        return -1;
+    sz = st->maxcount + 1 + st->maxcount / 2;
+    if (!(p = msi_realloc( st->strings, sz * sizeof(*p) ))) return -1;
+    memset( p + st->maxcount, 0, (sz - st->maxcount) * sizeof(*p) );
 
-    s = msi_realloc( st->sorted, sz*sizeof(UINT) );
-    if( !s )
+    if (!(s = msi_realloc( st->sorted, sz * sizeof(*s) )))
     {
         msi_free( p );
         return -1;
diff --git a/dlls/msi/where.c b/dlls/msi/where.c
index 2a64de8cd9d..684d9d5fb98 100644
--- a/dlls/msi/where.c
+++ b/dlls/msi/where.c
@@ -131,9 +131,10 @@ static UINT add_row(MSIWHEREVIEW *wv, UINT vals[])
         MSIROWENTRY **new_reorder;
         UINT newsize = wv->reorder_size * 2;
 
-        new_reorder = msi_realloc_zero(wv->reorder, sizeof(MSIROWENTRY *) * newsize);
+        new_reorder = msi_realloc(wv->reorder, newsize * sizeof(*new_reorder));
         if (!new_reorder)
             return ERROR_OUTOFMEMORY;
+        memset(new_reorder + wv->reorder_size, 0, (newsize - wv->reorder_size) * sizeof(*new_reorder));
 
         wv->reorder = new_reorder;
         wv->reorder_size = newsize;




More information about the wine-cvs mailing list