Commit 7d2173a9 authored by Marcus Meissner's avatar Marcus Meissner Committed by Alexandre Julliard

Do not free the old string in SysReAllocStringLen, reuse the old

string memory (if 'in' is NULL).
parent 9e405708
......@@ -206,16 +206,26 @@ int WINAPI SysReAllocStringLen(BSTR* old, const OLECHAR* in, unsigned int len)
if (old==NULL)
return 0;
/*
* Make sure we free the old string.
*/
if (*old!=NULL)
SysFreeString(*old);
/*
* Allocate the new string
*/
*old = SysAllocStringLen(in, len);
if (*old!=NULL) {
DWORD newbytelen = len*sizeof(WCHAR);
DWORD *ptr = HeapReAlloc(GetProcessHeap(),0,((DWORD*)*old)-1,newbytelen+sizeof(WCHAR)+sizeof(DWORD));
*old = (BSTR)(ptr+1);
*ptr = newbytelen;
if (in) {
memcpy(*old, in, newbytelen);
(*old)[len] = 0;
} else {
/* Subtle hidden feature: The old string data is still there
* when 'in' is NULL!
* Some Microsoft program needs it.
*/
}
} else {
/*
* Allocate the new string
*/
*old = SysAllocStringLen(in, len);
}
return 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