Dmitry Timoshkov : windowscodecs: Avoid unnecessary memory allocations.
Alexandre Julliard
julliard at winehq.org
Fri Sep 21 14:22:39 CDT 2012
Module: wine
Branch: master
Commit: 6715b186f66b14e70a7c587311861fbc3cc887c6
URL: http://source.winehq.org/git/wine.git/?a=commit;h=6715b186f66b14e70a7c587311861fbc3cc887c6
Author: Dmitry Timoshkov <dmitry at baikal.ru>
Date: Fri Sep 21 09:42:37 2012 +0900
windowscodecs: Avoid unnecessary memory allocations.
---
dlls/windowscodecs/gifformat.c | 19 +++++++------------
1 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/dlls/windowscodecs/gifformat.c b/dlls/windowscodecs/gifformat.c
index 1dce11d..81bde20 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;
More information about the wine-cvs
mailing list