@@ -8981,42 +8981,33 @@ os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal)
8981
8981
8982
8982
Py_RETURN_NONE ;
8983
8983
#else /* !MS_WINDOWS */
8984
- PyObject * result ;
8985
8984
DWORD sig = (DWORD )signal ;
8986
- DWORD err ;
8987
- HANDLE handle ;
8988
8985
8989
8986
#ifdef HAVE_WINDOWS_CONSOLE_IO
8990
8987
/* Console processes which share a common console can be sent CTRL+C or
8991
8988
CTRL+BREAK events, provided they handle said events. */
8992
8989
if (sig == CTRL_C_EVENT || sig == CTRL_BREAK_EVENT ) {
8993
8990
if (GenerateConsoleCtrlEvent (sig , (DWORD )pid ) == 0 ) {
8994
- err = GetLastError ();
8995
- PyErr_SetFromWindowsErr (err );
8996
- }
8997
- else {
8998
- Py_RETURN_NONE ;
8991
+ return PyErr_SetFromWindowsErr (0 );
8999
8992
}
8993
+ Py_RETURN_NONE ;
9000
8994
}
9001
8995
#endif /* HAVE_WINDOWS_CONSOLE_IO */
9002
8996
9003
8997
/* If the signal is outside of what GenerateConsoleCtrlEvent can use,
9004
8998
attempt to open and terminate the process. */
9005
- handle = OpenProcess (PROCESS_ALL_ACCESS , FALSE, (DWORD )pid );
8999
+ HANDLE handle = OpenProcess (PROCESS_ALL_ACCESS , FALSE, (DWORD )pid );
9006
9000
if (handle == NULL ) {
9007
- err = GetLastError ();
9008
- return PyErr_SetFromWindowsErr (err );
9001
+ return PyErr_SetFromWindowsErr (0 );
9009
9002
}
9010
9003
9011
- if (TerminateProcess (handle , sig ) == 0 ) {
9012
- err = GetLastError ();
9013
- result = PyErr_SetFromWindowsErr (err );
9014
- } else {
9015
- result = Py_NewRef (Py_None );
9004
+ BOOL res = TerminateProcess (handle , sig );
9005
+ CloseHandle (handle );
9006
+ if (res == 0 ) {
9007
+ return PyErr_SetFromWindowsErr (0 );
9016
9008
}
9017
9009
9018
- CloseHandle (handle );
9019
- return result ;
9010
+ Py_RETURN_NONE ;
9020
9011
#endif /* !MS_WINDOWS */
9021
9012
}
9022
9013
#endif /* HAVE_KILL */
0 commit comments