Skip to content

Commit 399d345

Browse files
committed
Fixed double Close on process handle
1 parent eb9db70 commit 399d345

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

contrib/win32/win32compat/signal.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -156,27 +156,6 @@ sw_raise(int sig) {
156156
return 0;
157157
}
158158

159-
int
160-
sw_kill(int pid, int sig) {
161-
int child_index, i;
162-
if (pid == GetCurrentProcessId())
163-
return sw_raise(sig);
164-
165-
/* for child processes - only SIGTERM supported*/
166-
/* TODO implement kill(SIGTERM) for child processes */
167-
child_index = -1;
168-
for (i = 0; i < children.num_children; i++)
169-
if (children.process_id[i] == pid) {
170-
child_index = i;
171-
break;
172-
}
173-
174-
if (child_index != -1)
175-
TerminateProcess(children.handles[child_index], 0);
176-
return 0;
177-
}
178-
179-
180159
/* processes pending signals, return EINTR if any are processed*/
181160
static int
182161
sw_process_pending_signals() {

contrib/win32/win32compat/signal_sigchld.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,26 @@ sw_child_to_zombie(DWORD index) {
127127
return 0;
128128
}
129129

130+
int
131+
sw_kill(int pid, int sig) {
132+
int child_index, i;
133+
if (pid == GetCurrentProcessId())
134+
return sw_raise(sig);
135+
136+
/* for child processes - only SIGTERM supported*/
137+
child_index = -1;
138+
for (i = 0; i < children.num_children; i++)
139+
if (children.process_id[i] == pid) {
140+
child_index = i;
141+
break;
142+
}
143+
144+
if (child_index != -1)
145+
TerminateProcess(children.handles[child_index], 0);
146+
return 0;
147+
}
148+
149+
130150
int waitpid(int pid, int *status, int options) {
131151
DWORD index, ret, ret_id, exit_code, timeout = 0;
132152
HANDLE process = NULL;
@@ -189,7 +209,7 @@ int waitpid(int pid, int *status, int options) {
189209
process = children.handles[index];
190210
ret_id = children.process_id[index];
191211
GetExitCodeProcess(process, &exit_code);
192-
CloseHandle(process);
212+
/* process handle will be closed when its removed from list */
193213
sw_remove_child_at_index(index);
194214
if (status)
195215
*status = exit_code;

0 commit comments

Comments
 (0)