Andrew Nguyen : gameux: Free the allocated GameStatisticsImpl object on failure in GameStatisticsMgrImpl ::GetGameStatistics.
Alexandre Julliard
julliard at winehq.org
Mon Jan 17 10:59:48 CST 2011
Module: wine
Branch: master
Commit: e6da2aec8f9e5bea9e0c857790c7dfaec4191fd7
URL: http://source.winehq.org/git/wine.git/?a=commit;h=e6da2aec8f9e5bea9e0c857790c7dfaec4191fd7
Author: Andrew Nguyen <anguyen at codeweavers.com>
Date: Sun Jan 16 03:41:49 2011 -0600
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 ecd518f..61df25e 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 c49e693..5bae4c8 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);
More information about the wine-cvs
mailing list