From b59e39b3eb7dd9ea2aa4de08de86f6c18492fcc7 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Fri, 5 Apr 2019 13:01:59 +0200 Subject: [PATCH] Fixed memory leak --- libfreerdp/core/test/TestConnect.c | 77 +++++++++++++------------------------- 1 file changed, 25 insertions(+), 52 deletions(-) diff --git a/libfreerdp/core/test/TestConnect.c b/libfreerdp/core/test/TestConnect.c index 7142a01..a3bdd27 100644 --- a/libfreerdp/core/test/TestConnect.c +++ b/libfreerdp/core/test/TestConnect.c @@ -170,7 +170,8 @@ static int testAbort(int port) static int testSuccess(int port) { - int rc; + int r; + int rc = -2; STARTUPINFOA si; PROCESS_INFORMATION process; char arg1[] = "/v:127.0.0.1:XXXXX"; @@ -182,66 +183,42 @@ static int testSuccess(int port) "/rfx", NULL }; - char* commandLine; + char* commandLine = NULL; int commandLineLen; int argc = 4; - char* path = TESTING_OUTPUT_DIRECTORY; - char* wpath = TESTING_SRC_DIRECTORY; - char* exe = GetCombinedPath(path, "server"); - char* wexe = GetCombinedPath(wpath, "server"); + char* path = NULL; + char* wpath = NULL; + char* exe = GetCombinedPath(TESTING_OUTPUT_DIRECTORY, "server"); + char* wexe = GetCombinedPath(TESTING_SRC_DIRECTORY, "server"); _snprintf(arg1, 18, "/v:127.0.0.1:%d", port); clientArgs[1] = arg1; if (!exe || !wexe) - { - free(exe); - free(wexe); - return -2; - } + goto fail; path = GetCombinedPath(exe, "Sample"); wpath = GetCombinedPath(wexe, "Sample"); - free(exe); - free(wexe); if (!path || !wpath) - { - free(path); - free(wpath); - return -2; - } + goto fail; exe = GetCombinedPath(path, "sfreerdp-server"); if (!exe) - { - free(path); - free(wpath); - return -2; - } + goto fail; printf("Sample Server: %s\n", exe); printf("Workspace: %s\n", wpath); if (!PathFileExistsA(exe)) - { - free(path); - free(wpath); - free(exe); - return -2; - } + goto fail; // Start sample server locally. commandLineLen = strlen(exe) + strlen("--local-only --port=XXXXX") + 1; commandLine = malloc(commandLineLen); if (!commandLine) - { - free(path); - free(wpath); - free(exe); - return -2; - } + goto fail; _snprintf(commandLine, commandLineLen, "%s --local-only --port=%d", exe, port); memset(&si, 0, sizeof(si)); @@ -249,33 +226,29 @@ static int testSuccess(int port) if (!CreateProcessA(exe, commandLine, NULL, NULL, FALSE, 0, NULL, wpath, &si, &process)) - { - free(exe); - free(path); - free(wpath); - return -2; - } + goto fail; - free(exe); - free(path); - free(wpath); - free(commandLine); Sleep(1 * 1000); /* let the server start */ - rc = runInstance(argc, clientArgs, NULL); + r = runInstance(argc, clientArgs, NULL); if (!TerminateProcess(process.hProcess, 0)) - return -2; + goto fail; WaitForSingleObject(process.hProcess, INFINITE); CloseHandle(process.hProcess); CloseHandle(process.hThread); - printf("%s: returned %d!\n", __FUNCTION__, rc); + printf("%s: returned %d!\n", __FUNCTION__, r); + rc = r; - if (rc) - return -1; + if (rc == 0) + printf("%s: Success!\n", __FUNCTION__); - printf("%s: Success!\n", __FUNCTION__); - return 0; +fail: + free(exe); + free(path); + free(wpath); + free(commandLine); + return rc; } int TestConnect(int argc, char* argv[]) -- 2.7.4