diff --git a/winpr/libwinpr/synch/test/TestSynchWaitableTimerAPC.c b/winpr/libwinpr/synch/test/TestSynchWaitableTimerAPC.c index 238472e75..f21e7f3c5 100644 --- a/winpr/libwinpr/synch/test/TestSynchWaitableTimerAPC.c +++ b/winpr/libwinpr/synch/test/TestSynchWaitableTimerAPC.c @@ -34,17 +34,18 @@ VOID CALLBACK TimerAPCProc(LPVOID lpArg, DWORD dwTimerLowValue, DWORD dwTimerHig int TestSynchWaitableTimerAPC(int argc, char* argv[]) { - HANDLE hTimer; + int status = -1; + HANDLE hTimer = NULL; BOOL bSuccess; LARGE_INTEGER due; - APC_DATA* apcData; + APC_DATA* apcData = NULL; apcData = (APC_DATA*) malloc(sizeof(APC_DATA)); g_Event = CreateEvent(NULL, TRUE, FALSE, NULL); hTimer = CreateWaitableTimer(NULL, FALSE, NULL); if (!hTimer) - return -1; + goto cleanup; due.QuadPart = -15000000LL; /* 1.5 seconds */ @@ -52,18 +53,24 @@ int TestSynchWaitableTimerAPC(int argc, char* argv[]) bSuccess = SetWaitableTimer(hTimer, &due, 2000, TimerAPCProc, apcData, FALSE); if (!bSuccess) - return -1; + goto cleanup; if (WaitForSingleObject(g_Event, INFINITE) != WAIT_OBJECT_0) { printf("WaitForSingleObject failed (%d)\n", GetLastError()); - return -1; + goto cleanup; } - CloseHandle(hTimer); - CloseHandle(g_Event); - free(apcData); + status = 0; - return 0; +cleanup: + if (hTime) + CloseHandle(hTimer); + if (g_Event) + CloseHandle(g_Event); + if (apcData) + free(apcData); + + return status; }