Browse Source

Don't try to kill a process which didn't start.

If CreateProcess() failed there's no sense trying to call
GetExitCodeProcess() or kill_process_tree().
Iain Patterson 10 years ago
parent
commit
4af002456a
1 changed files with 8 additions and 5 deletions
  1. 8 5
      service.cpp

+ 8 - 5
service.cpp

@@ -551,12 +551,14 @@ void CALLBACK end_service(void *arg, unsigned char why) {
   /* Check exit code */
   /* Check exit code */
   unsigned long exitcode = 0;
   unsigned long exitcode = 0;
   TCHAR code[16];
   TCHAR code[16];
-  GetExitCodeProcess(service->process_handle, &exitcode);
-  if (exitcode == STILL_ACTIVE || get_process_exit_time(service->process_handle, &service->exit_time)) GetSystemTimeAsFileTime(&service->exit_time);
-  CloseHandle(service->process_handle);
+  if (service->process_handle) {
+    GetExitCodeProcess(service->process_handle, &exitcode);
+    if (exitcode == STILL_ACTIVE || get_process_exit_time(service->process_handle, &service->exit_time)) GetSystemTimeAsFileTime(&service->exit_time);
+    CloseHandle(service->process_handle);
+  }
+  else GetSystemTimeAsFileTime(&service->exit_time);
 
 
   service->process_handle = 0;
   service->process_handle = 0;
-  service->pid = 0;
 
 
   /*
   /*
     Log that the service ended BEFORE logging about killing the process
     Log that the service ended BEFORE logging about killing the process
@@ -569,7 +571,8 @@ void CALLBACK end_service(void *arg, unsigned char why) {
 
 
   /* Clean up. */
   /* Clean up. */
   if (exitcode == STILL_ACTIVE) exitcode = 0;
   if (exitcode == STILL_ACTIVE) exitcode = 0;
-  kill_process_tree(service, service->pid, exitcode, service->pid);
+  if (service->pid) kill_process_tree(service, service->pid, exitcode, service->pid);
+  service->pid = 0;
 
 
   /*
   /*
     The why argument is true if our wait timed out or false otherwise.
     The why argument is true if our wait timed out or false otherwise.