goptions: free opt types on exit from edit options view
authorJens Axboe <axboe@kernel.dk>
Tue, 20 Mar 2012 07:31:29 +0000 (08:31 +0100)
committerJens Axboe <axboe@kernel.dk>
Tue, 20 Mar 2012 07:31:29 +0000 (08:31 +0100)
Signed-off-by: Jens Axboe <axboe@kernel.dk>
goptions.c

index f671dbec1c9e0f43b57285b854c32892ab151a7c..ebb5c2d692bc4f2b0ea28a5d3d70870bd0f8a4a9 100644 (file)
@@ -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;
 }