Do not free the old string in SysReAllocStringLen, reuse the old
string memory (if 'in' is NULL).
This commit is contained in:
parent
9e40570812
commit
7d2173a9e9
|
@ -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) {
|
||||
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.
|
||||
*/
|
||||
if (*old!=NULL)
|
||||
SysFreeString(*old);
|
||||
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Allocate the new string
|
||||
*/
|
||||
*old = SysAllocStringLen(in, len);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue