From: Guus Sliepen Date: Tue, 6 Mar 2018 18:31:17 +0000 (+0100) Subject: Ensure we call CloseServiceHandle() in case of errors. X-Git-Tag: release-1.1pre16~10 X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=69a18395931d657b77641b68ca12473ad6b996da;p=tinc Ensure we call CloseServiceHandle() in case of errors. --- diff --git a/src/tincctl.c b/src/tincctl.c index 54816a3d..5ba71613 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -722,19 +722,20 @@ static bool remove_service(void) { SC_HANDLE manager = NULL; SC_HANDLE service = NULL; SERVICE_STATUS status = {0}; + bool success = false; manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if(!manager) { fprintf(stderr, "Could not open service manager: %s\n", winerror(GetLastError())); - return false; + goto exit; } service = OpenService(manager, identname, SERVICE_ALL_ACCESS); if(!service) { fprintf(stderr, "Could not open %s service: %s\n", identname, winerror(GetLastError())); - return false; + goto exit; } if(!ControlService(service, SERVICE_CONTROL_STOP, &status)) { @@ -745,9 +746,13 @@ static bool remove_service(void) { if(!DeleteService(service)) { fprintf(stderr, "Could not remove %s service: %s\n", identname, winerror(GetLastError())); - return false; + goto exit; } + success = true; + +exit: + if(service) { CloseServiceHandle(service); } @@ -756,9 +761,11 @@ static bool remove_service(void) { CloseServiceHandle(manager); } - fprintf(stderr, "%s service removed\n", identname); + if(success) { + fprintf(stderr, "%s service removed\n", identname); + } - return true; + return success; } #endif