@@ -9533,42 +9533,33 @@ os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal)
9533
9533
9534
9534
Py_RETURN_NONE ;
9535
9535
#else /* !MS_WINDOWS */
9536
- PyObject * result ;
9537
9536
DWORD sig = (DWORD )signal ;
9538
- DWORD err ;
9539
- HANDLE handle ;
9540
9537
9541
9538
#ifdef HAVE_WINDOWS_CONSOLE_IO
9542
9539
/* Console processes which share a common console can be sent CTRL+C or
9543
9540
CTRL+BREAK events, provided they handle said events. */
9544
9541
if (sig == CTRL_C_EVENT || sig == CTRL_BREAK_EVENT ) {
9545
9542
if (GenerateConsoleCtrlEvent (sig , (DWORD )pid ) == 0 ) {
9546
- err = GetLastError ();
9547
- PyErr_SetFromWindowsErr (err );
9548
- }
9549
- else {
9550
- Py_RETURN_NONE ;
9543
+ return PyErr_SetFromWindowsErr (0 );
9551
9544
}
9545
+ Py_RETURN_NONE ;
9552
9546
}
9553
9547
#endif /* HAVE_WINDOWS_CONSOLE_IO */
9554
9548
9555
9549
/* If the signal is outside of what GenerateConsoleCtrlEvent can use,
9556
9550
attempt to open and terminate the process. */
9557
- handle = OpenProcess (PROCESS_ALL_ACCESS , FALSE, (DWORD )pid );
9551
+ HANDLE handle = OpenProcess (PROCESS_ALL_ACCESS , FALSE, (DWORD )pid );
9558
9552
if (handle == NULL ) {
9559
- err = GetLastError ();
9560
- return PyErr_SetFromWindowsErr (err );
9553
+ return PyErr_SetFromWindowsErr (0 );
9561
9554
}
9562
9555
9563
- if (TerminateProcess (handle , sig ) == 0 ) {
9564
- err = GetLastError ();
9565
- result = PyErr_SetFromWindowsErr (err );
9566
- } else {
9567
- result = Py_NewRef (Py_None );
9556
+ BOOL res = TerminateProcess (handle , sig );
9557
+ CloseHandle (handle );
9558
+ if (res == 0 ) {
9559
+ return PyErr_SetFromWindowsErr (0 );
9568
9560
}
9569
9561
9570
- CloseHandle (handle );
9571
- return result ;
9562
+ Py_RETURN_NONE ;
9572
9563
#endif /* !MS_WINDOWS */
9573
9564
}
9574
9565
#endif /* HAVE_KILL */
0 commit comments