Skip to content

Commit

Permalink
curses: Factor out dialog release to separate function.
Browse files Browse the repository at this point in the history
* pinentry/pinentry-curses.c (dialog_release): New.
(dialog_run): Use unified cleanup function to avoid code duplication
and memory leaks.

--

GnuPG-bug-id: 7218
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
  • Loading branch information
Jakuje authored and NIIBE Yutaka committed Sep 9, 2024
1 parent f4be34f commit 7f9f6ba
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions pinentry/pinentry-curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,24 @@ dialog_switch_pos (dialog_t diag, dialog_pos_t new_pos)
return 0;
}

static void
dialog_release (dialog_t diag)
{
free (diag->ok);
free (diag->repeat_ok);
free (diag->repeat_error);
if (diag->cancel)
free (diag->cancel);
if (diag->notok)
free (diag->notok);

if (diag->repeat_pin)
secmem_free (diag->repeat_pin);

if (diag->error)
free (diag->error);
}

/* XXX Assume that field width is at least > 5. */
static void
dialog_input (dialog_t diag, int alt, int chr)
Expand Down Expand Up @@ -1514,6 +1532,7 @@ dialog_run (pinentry_t pinentry, const char *tty_name, const char *tty_type)
fclose (ttyfi);
if (ttyfo)
fclose (ttyfo);
dialog_release (&diag);
return -2;
}
dialog_switch_pos (&diag, confirm_mode? DIALOG_POS_OK : DIALOG_POS_PIN);
Expand Down Expand Up @@ -1719,12 +1738,7 @@ dialog_run (pinentry_t pinentry, const char *tty_name, const char *tty_type)
fclose (ttyfi);
if (ttyfo)
fclose (ttyfo);
/* XXX Factor out into dialog_release or something. */
free (diag.ok);
if (diag.cancel)
free (diag.cancel);
if (diag.notok)
free (diag.notok);
dialog_release (&diag);

if (!confirm_mode)
{
Expand All @@ -1740,12 +1754,6 @@ dialog_run (pinentry_t pinentry, const char *tty_name, const char *tty_type)
}
}

if (diag.repeat_pin)
secmem_free (diag.repeat_pin);

if (diag.error)
free (diag.error);

if (done == -2)
pinentry->canceled = 1;

Expand Down

0 comments on commit 7f9f6ba

Please sign in to comment.