Don't leak hook startup handles.
authorIain Patterson <me@iain.cx>
Wed, 7 Sep 2016 14:12:42 +0000 (15:12 +0100)
committerIain Patterson <me@iain.cx>
Wed, 7 Sep 2016 14:12:42 +0000 (15:12 +0100)
When sharing I/O settings we dup the service's I/O handles then call
CreateProcess() to run the hook.  However we didn't explicitly close the
duplicated handles, so the subsequent CloseHandle() called by
cleanup_loggers() would hang, as the logging thread's ReadFile() won't
have completed due to the duplicated handle still being a potential
writer.

hook.cpp

index 6671d3b..abe4577 100644 (file)
--- a/hook.cpp
+++ b/hook.cpp
@@ -356,6 +356,7 @@ int nssm_hook(hook_thread_t *hook_threads, nssm_service_t *service, TCHAR *hook_
 #endif\r
   ret = NSSM_HOOK_STATUS_NOTRUN;\r
   if (CreateProcess(0, cmd, 0, 0, inherit_handles, flags, 0, service->dir, &si, &pi)) {\r
+    close_output_handles(&si);\r
     hook->name = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, HOOK_NAME_LENGTH * sizeof(TCHAR));\r
     if (hook->name) _sntprintf_s(hook->name, HOOK_NAME_LENGTH, _TRUNCATE, _T("%s (%s/%s)"), service->name, hook_event, hook_action);\r
     hook->process_handle = pi.hProcess;\r