Don't close process handle provided by WaitForDebugEvent
authorHannes Domani <ssbssa@yahoo.de>
Sun, 24 May 2020 22:18:25 +0000 (00:18 +0200)
committerHannes Domani <ssbssa@yahoo.de>
Wed, 27 May 2020 17:20:01 +0000 (19:20 +0200)
Only the process handle returned by OpenProcess or CreateProcess needs to
be closed, the one provided by WaitForDebugEvent is closed automatically.

gdbserver/ChangeLog:

2020-05-27  Hannes Domani  <ssbssa@yahoo.de>

* win32-low.cc (do_initial_child_stuff): Set open_process_used.
(win32_clear_inferiors): Use open_process_used.
(get_child_debug_event): Likewise.

gdbserver/ChangeLog
gdbserver/win32-low.cc

index 2b7fbb7c570d593065091c6711445be0eaf92931..678689530faff75d0722943f00787e7f5acd7d73 100644 (file)
@@ -1,3 +1,9 @@
+2020-05-27  Hannes Domani  <ssbssa@yahoo.de>
+
+       * win32-low.cc (do_initial_child_stuff): Set open_process_used.
+       (win32_clear_inferiors): Use open_process_used.
+       (get_child_debug_event): Likewise.
+
 2020-05-25  Michael Weghorn  <m.weghorn@posteo.de>
 
        PR gdbserver/25893
index d5555a78fd2a6be84d806deb8816cdbf73e2b917..a42fe25a2205a21f570fd80e07b887797f116669 100644 (file)
@@ -88,6 +88,9 @@ static int soft_interrupt_requested = 0;
    by suspending all the threads.  */
 static int faked_breakpoint = 0;
 
+/* True if current_process_handle needs to be closed.  */
+static bool open_process_used = false;
+
 #ifdef __x86_64__
 bool wow64_process = false;
 #endif
@@ -383,6 +386,7 @@ do_initial_child_stuff (HANDLE proch, DWORD pid, int attached)
 
   soft_interrupt_requested = 0;
   faked_breakpoint = 0;
+  open_process_used = true;
 
   memset (&current_event, 0, sizeof (current_event));
 
@@ -859,8 +863,11 @@ windows_nat::handle_output_debug_string (struct target_waitstatus *ourstatus)
 static void
 win32_clear_inferiors (void)
 {
-  if (current_process_handle != NULL)
-    CloseHandle (current_process_handle);
+  if (open_process_used)
+    {
+      CloseHandle (current_process_handle);
+      open_process_used = false;
+    }
 
   for_each_thread (delete_thread_info);
   siginfo_er.ExceptionCode = 0;
@@ -1513,6 +1520,12 @@ get_child_debug_event (DWORD *continue_status,
                (unsigned) current_event.dwThreadId));
       CloseHandle (current_event.u.CreateProcessInfo.hFile);
 
+      if (open_process_used)
+       {
+         CloseHandle (current_process_handle);
+         open_process_used = false;
+       }
+
       current_process_handle = current_event.u.CreateProcessInfo.hProcess;
       main_thread_id = current_event.dwThreadId;
 
@@ -1560,8 +1573,6 @@ get_child_debug_event (DWORD *continue_status,
          }
       }
       child_continue (DBG_CONTINUE, desired_stop_thread_id);
-      CloseHandle (current_process_handle);
-      current_process_handle = NULL;
       break;
 
     case LOAD_DLL_DEBUG_EVENT:
This page took 0.031242 seconds and 4 git commands to generate.