gameux: Free the allocated GameStatisticsImpl object on failure in GameStatisticsMgrImpl::GetGameStatistics.

Spotted with Valgrind.
This commit is contained in:
Andrew Nguyen 2011-01-16 03:41:49 -06:00 committed by Alexandre Julliard
parent 3e2bf8adb0
commit e6da2aec8f
2 changed files with 14 additions and 3 deletions

View File

@ -1086,7 +1086,8 @@ static HRESULT STDMETHODCALLTYPE GameStatisticsMgrImpl_GetGameStatistics(
{
HRESULT hr;
WCHAR lpApplicationId[49];
GameStatisticsImpl *statisticsImpl;
GameStatisticsImpl *statisticsImpl = NULL;
IGameStatistics *output_iface;
TRACE("(%p, %s, 0x%x, %p, %p)\n", iface, debugstr_w(GDFBinaryPath), openType, pOpenResult, ppiStats);
@ -1097,13 +1098,21 @@ static HRESULT STDMETHODCALLTYPE GameStatisticsMgrImpl_GetGameStatistics(
if(SUCCEEDED(hr))
{
*ppiStats = IGameStatistics_from_impl(statisticsImpl);
output_iface = IGameStatistics_from_impl(statisticsImpl);
hr = GAMEUX_buildStatisticsFilePath(lpApplicationId, statisticsImpl->stats.sStatsFile);
}
if(SUCCEEDED(hr))
hr = GAMEUX_loadGameStatistics(&statisticsImpl->stats, lpApplicationId, openType, pOpenResult);
if(SUCCEEDED(hr))
*ppiStats = output_iface;
else
{
HeapFree(GetProcessHeap(), 0, statisticsImpl);
*ppiStats = NULL;
}
return hr;
}

View File

@ -225,7 +225,7 @@ static void test_gamestatisticsmgr( void )
WORD wMaxStatsPerCategory = 0, wMaxCategories = 0;
IGameStatisticsMgr* gsm = NULL;
IGameStatistics* gs = NULL;
IGameStatistics* gs;
hr = CoCreateInstance( &CLSID_GameStatistics, NULL, CLSCTX_INPROC_SERVER, &IID_IGameStatisticsMgr, (LPVOID*)&gsm);
ok(hr == S_OK, "IGameStatisticsMgr creating failed (result false)\n");
@ -233,8 +233,10 @@ static void test_gamestatisticsmgr( void )
/* test trying to create interface IGameStatistics using GetGameStatistics method */
/* this should fail, cause statistics doesn't yet exists */
gs = (void *)0xdeadbeef;
hr = IGameStatisticsMgr_GetGameStatistics(gsm, sExeName, GAMESTATS_OPEN_OPENONLY, &dwOpenResult, &gs);
ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "GetGameStatistics returned unexpected value: 0x%08x\n", hr);
ok(gs == NULL, "Expected output pointer to be NULL, got %p\n", gs);
/* now, allow to create */
hr = IGameStatisticsMgr_GetGameStatistics(gsm, sExeName, GAMESTATS_OPEN_OPENORCREATE, &dwOpenResult, &gs);