shdocvw: Correct misuse of output pointer in get_profile_string helper.

This commit is contained in:
Andrew Nguyen 2010-12-07 03:13:02 -06:00 committed by Alexandre Julliard
parent 1c51015068
commit 5bdcd79c2e
1 changed files with 25 additions and 16 deletions

View File

@ -416,23 +416,32 @@ static DWORD get_profile_string(LPCWSTR lpAppName, LPCWSTR lpKeyName,
LPCWSTR lpFileName, WCHAR **rString ) LPCWSTR lpFileName, WCHAR **rString )
{ {
DWORD r = 0; DWORD r = 0;
DWORD len=128; DWORD len = 128;
WCHAR *buffer;
*rString = CoTaskMemAlloc(len*sizeof(WCHAR)); buffer = CoTaskMemAlloc(len * sizeof(*buffer));
if (rString != NULL) if (buffer != NULL)
{ {
r = GetPrivateProfileStringW(lpAppName, lpKeyName, NULL, *rString, len, lpFileName); r = GetPrivateProfileStringW(lpAppName, lpKeyName, NULL, buffer, len, lpFileName);
while (r == len-1) while (r == len-1)
{ {
CoTaskMemFree(rString); WCHAR *realloc_buf;
len *= 2; len *= 2;
rString = CoTaskMemAlloc(len*sizeof(WCHAR)); realloc_buf = CoTaskMemRealloc(buffer, len * sizeof(*buffer));
if (rString == NULL) if (realloc_buf == NULL)
break; {
r = GetPrivateProfileStringW(lpAppName, lpKeyName, NULL, *rString, len, lpFileName); CoTaskMemFree(buffer);
*rString = NULL;
return 0;
}
buffer = realloc_buf;
r = GetPrivateProfileStringW(lpAppName, lpKeyName, NULL, buffer, len, lpFileName);
} }
} }
*rString = buffer;
return r; return r;
} }
@ -456,12 +465,17 @@ static HRESULT WINAPI PersistFile_Load(IPersistFile *pFile, LPCOLESTR pszFileNam
r = get_profile_string(str_header, str_URL, pszFileName, &url); r = get_profile_string(str_header, str_URL, pszFileName, &url);
if (r == 0) if (url == NULL)
{
hr = E_OUTOFMEMORY;
CoTaskMemFree(filename);
}
else if (r == 0)
{ {
hr = E_FAIL; hr = E_FAIL;
CoTaskMemFree(filename); CoTaskMemFree(filename);
} }
else if (url != NULL) else
{ {
hr = S_OK; hr = S_OK;
CoTaskMemFree(This->currentFile); CoTaskMemFree(This->currentFile);
@ -470,11 +484,6 @@ static HRESULT WINAPI PersistFile_Load(IPersistFile *pFile, LPCOLESTR pszFileNam
This->url = url; This->url = url;
This->isDirty = FALSE; This->isDirty = FALSE;
} }
else
{
hr = E_OUTOFMEMORY;
CoTaskMemFree(filename);
}
/* Now we're going to read in the iconfile and iconindex. /* Now we're going to read in the iconfile and iconindex.
If we don't find them, that's not a failure case -- it's possible If we don't find them, that's not a failure case -- it's possible