Commit 6715b186 authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

windowscodecs: Avoid unnecessary memory allocations.

parent 0b40c9cb
...@@ -413,10 +413,7 @@ static HRESULT load_APE_metadata(IStream *stream, const GUID *vendor, DWORD opti ...@@ -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].id.u.pwszVal = strdupAtoW("Data");
result[1].value.vt = VT_UI1|VT_VECTOR; result[1].value.vt = VT_UI1|VT_VECTOR;
result[1].value.u.caub.cElems = data_size; result[1].value.u.caub.cElems = data_size;
result[1].value.u.caub.pElems = HeapAlloc(GetProcessHeap(), 0, data_size); result[1].value.u.caub.pElems = data;
memcpy(result[1].value.u.caub.pElems, data, data_size);
HeapFree(GetProcessHeap(), 0, data);
*items = result; *items = result;
*count = 2; *count = 2;
...@@ -449,7 +446,7 @@ static HRESULT load_GifComment_metadata(IStream *stream, const GUID *vendor, DWO ...@@ -449,7 +446,7 @@ static HRESULT load_GifComment_metadata(IStream *stream, const GUID *vendor, DWO
ULONG bytesread, data_size; ULONG bytesread, data_size;
MetadataItem *result; MetadataItem *result;
BYTE subblock_size; BYTE subblock_size;
BYTE *data; char *data;
*items = NULL; *items = NULL;
*count = 0; *count = 0;
...@@ -474,10 +471,10 @@ static HRESULT load_GifComment_metadata(IStream *stream, const GUID *vendor, DWO ...@@ -474,10 +471,10 @@ static HRESULT load_GifComment_metadata(IStream *stream, const GUID *vendor, DWO
if (!subblock_size) break; if (!subblock_size) break;
if (!data) if (!data)
data = HeapAlloc(GetProcessHeap(), 0, subblock_size); data = HeapAlloc(GetProcessHeap(), 0, subblock_size + 1);
else 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) if (!new_data)
{ {
HeapFree(GetProcessHeap(), 0, data); HeapFree(GetProcessHeap(), 0, data);
...@@ -494,6 +491,8 @@ static HRESULT load_GifComment_metadata(IStream *stream, const GUID *vendor, DWO ...@@ -494,6 +491,8 @@ static HRESULT load_GifComment_metadata(IStream *stream, const GUID *vendor, DWO
data_size += subblock_size; data_size += subblock_size;
} }
data[data_size] = 0;
result = HeapAlloc(GetProcessHeap(), 0, sizeof(MetadataItem)); result = HeapAlloc(GetProcessHeap(), 0, sizeof(MetadataItem));
if (!result) if (!result)
{ {
...@@ -508,11 +507,7 @@ static HRESULT load_GifComment_metadata(IStream *stream, const GUID *vendor, DWO ...@@ -508,11 +507,7 @@ static HRESULT load_GifComment_metadata(IStream *stream, const GUID *vendor, DWO
result->id.vt = VT_LPWSTR; result->id.vt = VT_LPWSTR;
result->id.u.pwszVal = strdupAtoW("TextEntry"); result->id.u.pwszVal = strdupAtoW("TextEntry");
result->value.vt = VT_LPSTR; result->value.vt = VT_LPSTR;
result->value.u.pszVal = HeapAlloc(GetProcessHeap(), 0, data_size + 1); result->value.u.pszVal = data;
memcpy(result->value.u.pszVal, data, data_size);
result->value.u.pszVal[data_size] = 0;
HeapFree(GetProcessHeap(), 0, data);
*items = result; *items = result;
*count = 1; *count = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment