1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00

Memory handling fixes when taking demo screenshots.

save_screenshot() returns a dynamically allocated error message in
case of failure, and Coverity complained of a memory leak when it was
ignored in putty.c.

The memory leak is trivial, because we were about to terminate the
process with an error anyway. But it's a good point that I forgot to
report the error!

Not critical enough to fix on 0.77 (where Coverity found it), but we
might as well make it look sensible on main.
This commit is contained in:
Simon Tatham 2022-05-08 08:51:45 +01:00
parent 9e4fe43a93
commit e29b6eb5d2
3 changed files with 13 additions and 5 deletions

View File

@ -621,11 +621,13 @@ static INT_PTR GenericMainDlgProc(HWND hwnd, UINT msg, WPARAM wParam,
if (dialog_box_demo_screenshot_filename &&
(UINT_PTR)wParam == DEMO_SCREENSHOT_TIMER_ID) {
KillTimer(hwnd, DEMO_SCREENSHOT_TIMER_ID);
const char *err = save_screenshot(
char *err = save_screenshot(
hwnd, dialog_box_demo_screenshot_filename);
if (err)
if (err) {
MessageBox(hwnd, err, "Demo screenshot failure",
MB_OK | MB_ICONERROR);
sfree(err);
}
ShinyEndDialog(hwnd, 0);
}
return 0;

View File

@ -180,7 +180,11 @@ const wchar_t *get_app_user_model_id(void)
static void demo_terminal_screenshot(void *ctx, unsigned long now)
{
HWND hwnd = (HWND)ctx;
save_screenshot(hwnd, terminal_demo_screenshot_filename);
char *err = save_screenshot(hwnd, terminal_demo_screenshot_filename);
if (err) {
MessageBox(hwnd, err, "Demo screenshot failure", MB_OK | MB_ICONERROR);
sfree(err);
}
cleanup_exit(0);
}

View File

@ -1592,10 +1592,12 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg,
case WM_TIMER:
if ((UINT_PTR)wParam == DEMO_SCREENSHOT_TIMER_ID) {
KillTimer(hwnd, DEMO_SCREENSHOT_TIMER_ID);
const char *err = save_screenshot(hwnd, demo_screenshot_filename);
if (err)
char *err = save_screenshot(hwnd, demo_screenshot_filename);
if (err) {
MessageBox(hwnd, err, "Demo screenshot failure",
MB_OK | MB_ICONERROR);
sfree(err);
}
EndDialog(hwnd, 0);
}
return 0;