From e6da2aec8f9e5bea9e0c857790c7dfaec4191fd7 Mon Sep 17 00:00:00 2001 From: Andrew Nguyen Date: Sun, 16 Jan 2011 03:41:49 -0600 Subject: [PATCH] gameux: Free the allocated GameStatisticsImpl object on failure in GameStatisticsMgrImpl::GetGameStatistics. Spotted with Valgrind. --- dlls/gameux/gamestatistics.c | 13 +++++++++++-- dlls/gameux/tests/gamestatistics.c | 4 +++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/dlls/gameux/gamestatistics.c b/dlls/gameux/gamestatistics.c index ecd518fabee..61df25e9bcc 100644 --- a/dlls/gameux/gamestatistics.c +++ b/dlls/gameux/gamestatistics.c @@ -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; } diff --git a/dlls/gameux/tests/gamestatistics.c b/dlls/gameux/tests/gamestatistics.c index c49e693511b..5bae4c8fb3c 100644 --- a/dlls/gameux/tests/gamestatistics.c +++ b/dlls/gameux/tests/gamestatistics.c @@ -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); -- 2.11.4.GIT