From 6715b186f66b14e70a7c587311861fbc3cc887c6 Mon Sep 17 00:00:00 2001 From: Dmitry Timoshkov Date: Fri, 21 Sep 2012 09:42:37 +0900 Subject: [PATCH] windowscodecs: Avoid unnecessary memory allocations. --- dlls/windowscodecs/gifformat.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/dlls/windowscodecs/gifformat.c b/dlls/windowscodecs/gifformat.c index 1dce11db335..81bde20ac26 100644 --- a/dlls/windowscodecs/gifformat.c +++ b/dlls/windowscodecs/gifformat.c @@ -413,10 +413,7 @@ static HRESULT load_APE_metadata(IStream *stream, const GUID *vendor, DWORD opti result[1].id.u.pwszVal = strdupAtoW("Data"); result[1].value.vt = VT_UI1|VT_VECTOR; result[1].value.u.caub.cElems = data_size; - result[1].value.u.caub.pElems = HeapAlloc(GetProcessHeap(), 0, data_size); - memcpy(result[1].value.u.caub.pElems, data, data_size); - - HeapFree(GetProcessHeap(), 0, data); + result[1].value.u.caub.pElems = data; *items = result; *count = 2; @@ -449,7 +446,7 @@ static HRESULT load_GifComment_metadata(IStream *stream, const GUID *vendor, DWO ULONG bytesread, data_size; MetadataItem *result; BYTE subblock_size; - BYTE *data; + char *data; *items = NULL; *count = 0; @@ -474,10 +471,10 @@ static HRESULT load_GifComment_metadata(IStream *stream, const GUID *vendor, DWO if (!subblock_size) break; if (!data) - data = HeapAlloc(GetProcessHeap(), 0, subblock_size); + data = HeapAlloc(GetProcessHeap(), 0, subblock_size + 1); else { - BYTE *new_data = HeapReAlloc(GetProcessHeap(), 0, data, data_size + subblock_size); + char *new_data = HeapReAlloc(GetProcessHeap(), 0, data, data_size + subblock_size + 1); if (!new_data) { HeapFree(GetProcessHeap(), 0, data); @@ -494,6 +491,8 @@ static HRESULT load_GifComment_metadata(IStream *stream, const GUID *vendor, DWO data_size += subblock_size; } + data[data_size] = 0; + result = HeapAlloc(GetProcessHeap(), 0, sizeof(MetadataItem)); if (!result) { @@ -508,11 +507,7 @@ static HRESULT load_GifComment_metadata(IStream *stream, const GUID *vendor, DWO result->id.vt = VT_LPWSTR; result->id.u.pwszVal = strdupAtoW("TextEntry"); result->value.vt = VT_LPSTR; - result->value.u.pszVal = HeapAlloc(GetProcessHeap(), 0, data_size + 1); - memcpy(result->value.u.pszVal, data, data_size); - result->value.u.pszVal[data_size] = 0; - - HeapFree(GetProcessHeap(), 0, data); + result->value.u.pszVal = data; *items = result; *count = 1;