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

string memory (if 'in' is NULL).
This commit is contained in:
Marcus Meissner 2003-01-28 00:30:29 +00:00 committed by Alexandre Julliard
parent 9e40570812
commit 7d2173a9e9
1 changed files with 20 additions and 10 deletions

View File

@ -206,16 +206,26 @@ int WINAPI SysReAllocStringLen(BSTR* old, const OLECHAR* in, unsigned int len)
if (old==NULL) if (old==NULL)
return 0; return 0;
/* if (*old!=NULL) {
* Make sure we free the old string. 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 * Allocate the new string
*/ */
*old = SysAllocStringLen(in, len); *old = SysAllocStringLen(in, len);
}
return 1; return 1;
} }