Browse Source

Don't leak hook startup handles.

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.
Iain Patterson 5 years ago
parent
commit
2d1226f847
1 changed files with 1 additions and 0 deletions
  1. 1 0
      hook.cpp

+ 1 - 0
hook.cpp

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