From 231edf61f9dd7ead3943454f25dde01c5863cfdb Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 20 Mar 2012 08:31:29 +0100 Subject: [PATCH] goptions: free opt types on exit from edit options view Signed-off-by: Jens Axboe --- goptions.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 9 deletions(-) diff --git a/goptions.c b/goptions.c index f671dbec..ebb5c2d6 100644 --- a/goptions.c +++ b/goptions.c @@ -95,7 +95,8 @@ static GtkWidget *gopt_get_group_frame(GtkWidget *box, unsigned int groupmask) /* * Mark children as invisible, if needed. */ -static void gopt_set_children_visible(struct fio_option *parent, gboolean visible) +static void gopt_set_children_visible(struct fio_option *parent, + gboolean visible) { struct fio_option *o; int i; @@ -137,7 +138,16 @@ static void gopt_mark_index(struct gopt *gopt, unsigned int idx) gopt_widgets[idx] = gopt->box; } -static struct gopt *gopt_new_str_store(struct fio_option *o, const char *text, unsigned int idx) +static void gopt_str_destroy(GtkWidget *w, gpointer data) +{ + struct gopt_str *s = (struct gopt_str *) data; + + free(s); + gtk_widget_destroy(w); +} + +static struct gopt *gopt_new_str_store(struct fio_option *o, const char *text, + unsigned int idx) { struct gopt_str *s; GtkWidget *label; @@ -157,6 +167,7 @@ static struct gopt *gopt_new_str_store(struct fio_option *o, const char *text, u gtk_entry_set_text(GTK_ENTRY(s->entry), text); gtk_entry_set_editable(GTK_ENTRY(s->entry), 1); s->gopt.sig_handler = g_signal_connect(GTK_OBJECT(s->entry), "changed", G_CALLBACK(gopt_str_changed), s); + g_signal_connect(GTK_OBJECT(s->entry), "destroy", G_CALLBACK(gopt_str_destroy), s); if (o->def) gtk_entry_set_text(GTK_ENTRY(s->entry), o->def); @@ -175,7 +186,16 @@ static void gopt_combo_changed(GtkComboBox *box, gpointer data) printf("combo %s changed\n", o->name); } -static struct gopt_combo *__gopt_new_combo(struct fio_option *o, unsigned int idx) +static void gopt_combo_destroy(GtkWidget *w, gpointer data) +{ + struct gopt_combo *c = (struct gopt_combo *) data; + + free(c); + gtk_widget_destroy(w); +} + +static struct gopt_combo *__gopt_new_combo(struct fio_option *o, + unsigned int idx) { struct gopt_combo *c; GtkWidget *label; @@ -192,6 +212,7 @@ static struct gopt_combo *__gopt_new_combo(struct fio_option *o, unsigned int id c->combo = gtk_combo_box_new_text(); gopt_mark_index(&c->gopt, idx); c->gopt.sig_handler = g_signal_connect(GTK_OBJECT(c->combo), "changed", G_CALLBACK(gopt_combo_changed), c); + g_signal_connect(GTK_OBJECT(c->combo), "destroy", G_CALLBACK(gopt_combo_destroy), c); gtk_box_pack_start(GTK_BOX(c->gopt.box), c->combo, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(c->gopt.box), label, FALSE, FALSE, 0); @@ -200,7 +221,8 @@ static struct gopt_combo *__gopt_new_combo(struct fio_option *o, unsigned int id return c; } -static struct gopt *gopt_new_combo_str(struct fio_option *o, const char *text, unsigned int idx) +static struct gopt *gopt_new_combo_str(struct fio_option *o, const char *text, + unsigned int idx) { struct gopt_combo *combo; struct value_pair *vp; @@ -224,7 +246,8 @@ static struct gopt *gopt_new_combo_str(struct fio_option *o, const char *text, u return &combo->gopt; } -static struct gopt *gopt_new_combo_int(struct fio_option *o, unsigned int *ip, unsigned int idx) +static struct gopt *gopt_new_combo_int(struct fio_option *o, unsigned int *ip, + unsigned int idx) { struct gopt_combo *combo; struct value_pair *vp; @@ -305,8 +328,16 @@ static void gopt_int_changed(GtkSpinButton *spin, gpointer data) } } -static struct gopt_int *__gopt_new_int(struct fio_option *o, unsigned long long *p, - unsigned int idx) +static void gopt_int_destroy(GtkWidget *w, gpointer data) +{ + struct gopt_int *i = (struct gopt_int *) data; + + free(i); + gtk_widget_destroy(w); +} + +static struct gopt_int *__gopt_new_int(struct fio_option *o, + unsigned long long *p, unsigned int idx) { unsigned long long defval; struct gopt_int *i; @@ -345,6 +376,7 @@ static struct gopt_int *__gopt_new_int(struct fio_option *o, unsigned long long gtk_spin_button_set_value(GTK_SPIN_BUTTON(i->spin), defval); i->lastval = defval; i->gopt.sig_handler = g_signal_connect(G_OBJECT(i->spin), "value-changed", G_CALLBACK(gopt_int_changed), i); + g_signal_connect(G_OBJECT(i->spin), "destroy", G_CALLBACK(gopt_int_destroy), i); gtk_box_pack_start(GTK_BOX(i->gopt.box), i->spin, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(i->gopt.box), label, FALSE, FALSE, 0); @@ -353,7 +385,8 @@ static struct gopt_int *__gopt_new_int(struct fio_option *o, unsigned long long return i; } -static struct gopt *gopt_new_int(struct fio_option *o, unsigned int *ip, unsigned int idx) +static struct gopt *gopt_new_int(struct fio_option *o, unsigned int *ip, + unsigned int idx) { unsigned long long ullp; struct gopt_int *i; @@ -397,7 +430,16 @@ static void gopt_bool_toggled(GtkToggleButton *button, gpointer data) gopt_set_children_visible(o, set); } -static struct gopt *gopt_new_bool(struct fio_option *o, unsigned int *val, unsigned int idx) +static void gopt_bool_destroy(GtkWidget *w, gpointer data) +{ + struct gopt_bool *b = (struct gopt_bool *) data; + + free(b); + gtk_widget_destroy(w); +} + +static struct gopt *gopt_new_bool(struct fio_option *o, unsigned int *val, + unsigned int idx) { struct gopt_bool *b; GtkWidget *label; @@ -423,6 +465,7 @@ static struct gopt *gopt_new_bool(struct fio_option *o, unsigned int *val, unsig gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b->check), defstate); b->gopt.sig_handler = g_signal_connect(G_OBJECT(b->check), "toggled", G_CALLBACK(gopt_bool_toggled), b); + g_signal_connect(G_OBJECT(b->check), "destroy", G_CALLBACK(gopt_bool_destroy), b); gtk_box_pack_start(GTK_BOX(b->gopt.box), b->check, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(b->gopt.box), label, FALSE, FALSE, 0); @@ -470,6 +513,14 @@ static void range_value_changed(GtkSpinButton *spin, gpointer data) } } +static void gopt_range_destroy(GtkWidget *w, gpointer data) +{ + struct gopt_range *r = (struct gopt_range *) data; + + free(r); + gtk_widget_destroy(w); +} + static struct gopt *gopt_new_int_range(struct fio_option *o, unsigned int **ip, unsigned int idx) { @@ -517,6 +568,7 @@ static struct gopt *gopt_new_int_range(struct fio_option *o, unsigned int **ip, } gtk_box_pack_start(GTK_BOX(r->gopt.box), label, FALSE, FALSE, 0); + g_signal_connect(G_OBJECT(r->gopt.box), "destroy", G_CALLBACK(gopt_range_destroy), r); o->gui_data = r; return &r->gopt; } -- 2.25.1