1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-25 01:02:24 +00:00

Tidy up 'eventlog_stuff' structure and fix leak.

This is the structure that stores the truncated version of the Event
Log data to be displayed by the GTK Event Log dialog. It persists for
the lifetime of the parent SSH window, so it was deliberate that it
wasn't freed on destruction of the dialog itself, but I also forgot to
free it on destruction of the SSH window. (This will be more important
in multi-connection process architectures like the OS X port, of
course.)

While I'm at it, I'll follow my recent practice by exposing the
structure tag outside gtkdlg.c so that callers can more easily not
confuse it with some other kind of void *.
This commit is contained in:
Simon Tatham 2018-10-08 19:30:01 +01:00
parent d624ae2ab5
commit a3a8b28528
3 changed files with 34 additions and 15 deletions

View File

@ -3772,7 +3772,7 @@ struct eventlog_stuff {
static void eventlog_destroy(GtkWidget *widget, gpointer data)
{
struct eventlog_stuff *es = (struct eventlog_stuff *)data;
eventlog_stuff *es = (eventlog_stuff *)data;
es->window = NULL;
sfree(es->seldata);
@ -3789,7 +3789,7 @@ static void eventlog_ok_handler(union control *ctrl, dlgparam *dp,
static void eventlog_list_handler(union control *ctrl, dlgparam *dp,
void *data, int event)
{
struct eventlog_stuff *es = (struct eventlog_stuff *)data;
eventlog_stuff *es = (eventlog_stuff *)data;
if (event == EVENT_REFRESH) {
int i;
@ -3868,7 +3868,7 @@ static void eventlog_list_handler(union control *ctrl, dlgparam *dp,
void eventlog_selection_get(GtkWidget *widget, GtkSelectionData *seldata,
guint info, guint time_stamp, gpointer data)
{
struct eventlog_stuff *es = (struct eventlog_stuff *)data;
eventlog_stuff *es = (eventlog_stuff *)data;
gtk_selection_data_set(seldata, gtk_selection_data_get_target(seldata), 8,
(unsigned char *)es->seldata, es->sellen);
@ -3877,7 +3877,7 @@ void eventlog_selection_get(GtkWidget *widget, GtkSelectionData *seldata,
gint eventlog_selection_clear(GtkWidget *widget, GdkEventSelection *seldata,
gpointer data)
{
struct eventlog_stuff *es = (struct eventlog_stuff *)data;
eventlog_stuff *es = (eventlog_stuff *)data;
struct uctrl *uc;
/*
@ -3901,9 +3901,8 @@ gint eventlog_selection_clear(GtkWidget *widget, GdkEventSelection *seldata,
return TRUE;
}
void showeventlog(void *estuff, void *parentwin)
void showeventlog(eventlog_stuff *es, void *parentwin)
{
struct eventlog_stuff *es = (struct eventlog_stuff *)estuff;
GtkWidget *window, *w0, *w1;
GtkWidget *parent = GTK_WIDGET(parentwin);
struct controlset *s0, *s1;
@ -3984,17 +3983,33 @@ void showeventlog(void *estuff, void *parentwin)
G_CALLBACK(eventlog_selection_clear), es);
}
void *eventlogstuff_new(void)
eventlog_stuff *eventlogstuff_new(void)
{
struct eventlog_stuff *es;
es = snew(struct eventlog_stuff);
eventlog_stuff *es = snew(eventlog_stuff);
memset(es, 0, sizeof(*es));
return es;
}
void logevent_dlg(void *estuff, const char *string)
void eventlogstuff_free(eventlog_stuff *es)
{
int i;
if (es->events_initial) {
for (i = 0; i < LOGEVENT_INITIAL_MAX; i++)
sfree(es->events_initial[i]);
sfree(es->events_initial);
}
if (es->events_circular) {
for (i = 0; i < LOGEVENT_CIRCULAR_MAX; i++)
sfree(es->events_circular[i]);
sfree(es->events_circular);
}
sfree(es);
}
void logevent_dlg(eventlog_stuff *es, const char *string)
{
struct eventlog_stuff *es = (struct eventlog_stuff *)estuff;
char timebuf[40];
struct tm tm;
char **location;

View File

@ -165,7 +165,7 @@ struct Frontend {
int exited;
struct unicode_data ucsdata;
Conf *conf;
void *eventlogstuff;
eventlog_stuff *eventlogstuff;
guint32 input_event_time; /* Timestamp of the most recent input event. */
GtkWidget *dialogs[DIALOG_SLOT_LIMIT];
#if GTK_CHECK_VERSION(3,4,0)
@ -2470,6 +2470,8 @@ static void delete_inst(Frontend *inst)
*/
delete_callbacks_for_context(inst);
eventlogstuff_free(inst->eventlogstuff);
sfree(inst);
}

View File

@ -219,9 +219,11 @@ GtkWidget *create_config_box(const char *title, Conf *conf,
#endif
void nonfatal_message_box(void *window, const char *msg);
void about_box(void *window);
void *eventlogstuff_new(void);
void showeventlog(void *estuff, void *parentwin);
void logevent_dlg(void *estuff, const char *string);
typedef struct eventlog_stuff eventlog_stuff;
eventlog_stuff *eventlogstuff_new(void);
void eventlogstuff_free(eventlog_stuff *);
void showeventlog(eventlog_stuff *estuff, void *parentwin);
void logevent_dlg(eventlog_stuff *estuff, const char *string);
#ifdef MAY_REFER_TO_GTK_IN_HEADERS
struct message_box_button {
const char *title;