mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
Close all thread handles returned from CreateThread.
If you don't, they are permanently leaked. A user points out that this is particularly bad in Pageant, with the new named-pipe-based IPC, since it will spawn an input and output I/O thread per named pipe connection, leading to two handles being leaked every time.
This commit is contained in:
parent
2029aa55c2
commit
c714dfc936
@ -481,8 +481,10 @@ struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata,
|
|||||||
h->u.i.flags = flags;
|
h->u.i.flags = flags;
|
||||||
|
|
||||||
ensure_ready_event_setup();
|
ensure_ready_event_setup();
|
||||||
CreateThread(NULL, 0, handle_input_threadfunc,
|
HANDLE hThread = CreateThread(NULL, 0, handle_input_threadfunc,
|
||||||
&h->u.i, 0, &in_threadid);
|
&h->u.i, 0, &in_threadid);
|
||||||
|
if (hThread)
|
||||||
|
CloseHandle(hThread); /* we don't need the thread handle */
|
||||||
h->u.i.busy = true;
|
h->u.i.busy = true;
|
||||||
|
|
||||||
return h;
|
return h;
|
||||||
@ -508,8 +510,10 @@ struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata,
|
|||||||
h->u.o.flags = flags;
|
h->u.o.flags = flags;
|
||||||
|
|
||||||
ensure_ready_event_setup();
|
ensure_ready_event_setup();
|
||||||
CreateThread(NULL, 0, handle_output_threadfunc,
|
HANDLE hThread = CreateThread(NULL, 0, handle_output_threadfunc,
|
||||||
&h->u.o, 0, &out_threadid);
|
&h->u.o, 0, &out_threadid);
|
||||||
|
if (hThread)
|
||||||
|
CloseHandle(hThread); /* we don't need the thread handle */
|
||||||
|
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
@ -1631,8 +1631,10 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
|
|||||||
DWORD wm_copydata_threadid;
|
DWORD wm_copydata_threadid;
|
||||||
wmct.ev_msg_ready = CreateEvent(NULL, false, false, NULL);
|
wmct.ev_msg_ready = CreateEvent(NULL, false, false, NULL);
|
||||||
wmct.ev_reply_ready = CreateEvent(NULL, false, false, NULL);
|
wmct.ev_reply_ready = CreateEvent(NULL, false, false, NULL);
|
||||||
CreateThread(NULL, 0, wm_copydata_threadfunc,
|
HANDLE hThread = CreateThread(NULL, 0, wm_copydata_threadfunc,
|
||||||
&inst, 0, &wm_copydata_threadid);
|
&inst, 0, &wm_copydata_threadid);
|
||||||
|
if (hThread)
|
||||||
|
CloseHandle(hThread); /* we don't need the thread handle */
|
||||||
add_handle_wait(wmct.ev_msg_ready, wm_copydata_got_msg, NULL);
|
add_handle_wait(wmct.ev_msg_ready, wm_copydata_got_msg, NULL);
|
||||||
|
|
||||||
if (show_keylist_on_startup)
|
if (show_keylist_on_startup)
|
||||||
|
@ -1160,13 +1160,15 @@ static void start_generating_key(HWND hwnd, struct MainDlgState *state)
|
|||||||
params->key = &state->key;
|
params->key = &state->key;
|
||||||
params->dsakey = &state->dsakey;
|
params->dsakey = &state->dsakey;
|
||||||
|
|
||||||
if (!CreateThread(NULL, 0, generate_key_thread,
|
HANDLE hThread = CreateThread(NULL, 0, generate_key_thread,
|
||||||
params, 0, &threadid)) {
|
params, 0, &threadid);
|
||||||
|
if (!hThread) {
|
||||||
MessageBox(hwnd, "Out of thread resources",
|
MessageBox(hwnd, "Out of thread resources",
|
||||||
"Key generation error",
|
"Key generation error",
|
||||||
MB_OK | MB_ICONERROR);
|
MB_OK | MB_ICONERROR);
|
||||||
sfree(params);
|
sfree(params);
|
||||||
} else {
|
} else {
|
||||||
|
CloseHandle(hThread); /* we don't need the thread handle */
|
||||||
state->generation_thread_exists = true;
|
state->generation_thread_exists = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5355,8 +5355,10 @@ static void wintw_clip_request_paste(TermWin *tw, int clipboard)
|
|||||||
* that tells us it's OK to paste.
|
* that tells us it's OK to paste.
|
||||||
*/
|
*/
|
||||||
DWORD in_threadid; /* required for Win9x */
|
DWORD in_threadid; /* required for Win9x */
|
||||||
CreateThread(NULL, 0, clipboard_read_threadfunc,
|
HANDLE hThread = CreateThread(NULL, 0, clipboard_read_threadfunc,
|
||||||
wgs.term_hwnd, 0, &in_threadid);
|
wgs.term_hwnd, 0, &in_threadid);
|
||||||
|
if (hThread)
|
||||||
|
CloseHandle(hThread); /* we don't need the thread handle */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user