Fixed memory leaks.
authorArmin Novak <armin.novak@gmail.com>
Sun, 16 Nov 2014 22:10:33 +0000 (23:10 +0100)
committerArmin Novak <armin.novak@gmail.com>
Sun, 16 Nov 2014 22:10:33 +0000 (23:10 +0100)
winpr/libwinpr/synch/test/TestSynchWaitableTimerAPC.c

index 238472e..f21e7f3 100644 (file)
@@ -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;
+
+cleanup:
+       if (hTime)
+               CloseHandle(hTimer);
+       if (g_Event)
+               CloseHandle(g_Event);
+       if (apcData)
+               free(apcData);
 
-       return 0;
+       return status;
 }