From 4c722e3d48b95204656f1ef698c09aaf8ec4cd27 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 23 Oct 2012 11:53:56 +0200 Subject: use libc memory allocation functions --- libmsi/msipriv.h | 16 +++++++++------- libmsi/streams.c | 3 ++- libmsi/string.c | 2 +- libmsi/where.c | 3 ++- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/libmsi/msipriv.h b/libmsi/msipriv.h index 8f98cdb..aff1951 100644 --- a/libmsi/msipriv.h +++ b/libmsi/msipriv.h @@ -521,30 +521,32 @@ static const WCHAR szInstallLocation[] = {'I','n','s','t','a','l','l','L','o','c 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(len, 1); } 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 void *msi_realloc_zero( void *mem, size_t oldlen, size_t len ) __WINE_ALLOC_SIZE(3); +static inline void *msi_realloc_zero( void *mem, size_t oldlen, size_t len ) { - return HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len ); + mem = realloc( mem, len ); + memset(mem + oldlen, 0, len - oldlen); + return mem; } static inline bool msi_free( void *mem ) { - return HeapFree( GetProcessHeap(), 0, mem ); + free(mem); } static inline char *strdupWtoA( const WCHAR *str ) diff --git a/libmsi/streams.c b/libmsi/streams.c index dabfef5..2f0d4ec 100644 --- a/libmsi/streams.c +++ b/libmsi/streams.c @@ -56,8 +56,9 @@ static bool streams_set_table_size(LibmsiStreamSVIEW *sv, unsigned size) { if (size >= sv->max_streams) { + sv->streams = msi_realloc_zero(sv->streams, sv->max_streams * sizeof(STREAM *), + sv->max_streams * 2 * sizeof(STREAM *)); sv->max_streams *= 2; - sv->streams = msi_realloc_zero(sv->streams, sv->max_streams * sizeof(STREAM *)); if (!sv->streams) return false; } diff --git a/libmsi/string.c b/libmsi/string.c index 39071e4..3b8c6ec 100644 --- a/libmsi/string.c +++ b/libmsi/string.c @@ -138,7 +138,7 @@ static int st_find_free_entry( string_table *st ) /* dynamically resize */ sz = st->maxcount + 1 + st->maxcount/2; - p = msi_realloc_zero( st->strings, sz * sizeof(struct msistring) ); + p = msi_realloc_zero( st->strings, st->maxcount * sizeof(struct msistring), sz * sizeof(struct msistring) ); if( !p ) return -1; diff --git a/libmsi/where.c b/libmsi/where.c index 2c10d18..87f9b07 100644 --- a/libmsi/where.c +++ b/libmsi/where.c @@ -130,7 +130,8 @@ static unsigned add_row(LibmsiWhereView *wv, unsigned vals[]) LibmsiRowEntry **new_reorder; unsigned newsize = wv->reorder_size * 2; - new_reorder = msi_realloc_zero(wv->reorder, sizeof(LibmsiRowEntry *) * newsize); + new_reorder = msi_realloc_zero(wv->reorder, sizeof(LibmsiRowEntry *) * wv->reorder_size, + sizeof(LibmsiRowEntry *) * newsize); if (!new_reorder) return ERROR_OUTOFMEMORY; -- cgit