title: GTK C segv: Adding new signal causes segv
body: <p>I am getting a sigsegv fault with the introduction of a new switch signal into an existing test gui.</p>
  
  <p>The UI has 3 possible sources of events, two event boxes and one switch. When the event boxes are clicked, they behave normally, however if the switch is toggled, then clicking on one of the event boxes results in a segv (behaviour 1). </p>
  
  <p>In addition, if run from new, toggling the switch first and then clicking on the event box also results in a segv (behaviour 2). The segv for both occurs always at the same place (if using one of the event boxes as an example) as follows:</p>
  
  <pre><code>if (((interface *) toggle)-&gt;eth0-&gt;ip_enabled) {
  </code></pre>
  
  <p>The simplest manifestation I could come up with in terms of code is as follows (excuse the includes):</p>
  
  <pre><code>/*
   * STRIPPED DOWN VERSION
   */
  #include &lt;arpa/inet.h&gt;
  #include &lt;gtk/gtk.h&gt;
  #include &lt;net/if.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;netinet/ip.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;sys/ioctl.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/wait.h&gt;
  #include &lt;unistd.h&gt;
  
  
  #define IPV4_ENABLED                1
  #define IPV4_DISABLED               0
  #define SELECTED                    1
  
  typedef struct {
      int ip_enabled;
  } net;
  
  typedef struct {
      net *eth0;
      net *wlan0;
      int type;
  } interface;
  
  typedef enum {
      IT_ETH0,
      IT_WLAN0,
      IT_UNASSIGNED = 999,
  } interface_type;
  
  typedef struct {
      int active;
      interface *port;
      int debug;
  } test_parameters;
  
  void wired (net *eth0);
  
  void wifi (net *wlan0);
  
  int main (int argc, char *argv[]) {
  
      GtkBuilder *builder;
      GtkWidget *window;
      GError *gtk_error = NULL;
  
      net *eth0 = g_slice_new (net);
      net *wlan0 = g_slice_new (net);
      interface *toggle = g_slice_new (interface);
  
      test_parameters *test = g_slice_new (test_parameters);
  
      test-&gt;port-&gt;type == IT_UNASSIGNED;
  
          /*Add interfaces to struct "interface" */
      toggle-&gt;eth0 = eth0;
      toggle-&gt;wlan0 = wlan0;
  
      toggle-&gt;eth0-&gt;ip_enabled = 0;
      toggle-&gt;wlan0-&gt;ip_enabled = 0;
  
      if (NULL == toggle-&gt;eth0)
          fprintf (stdout, "%s\n", "eth0 is null ");
  
      if (NULL == toggle-&gt;wlan0)
          fprintf (stdout, "%s\n", "wlan0 is null ");
  
  
      gtk_init (&amp;argc, &amp;argv);
  
      builder = gtk_builder_new ();
      if (!gtk_builder_add_from_file (builder, "glade/window_main.glade", NULL)) {
          fprintf (stdout, "%s%s\n", "Error loading file with the reason: ", gtk_error-&gt;message);
          g_free (gtk_error);
          exit (EXIT_FAILURE);
      }
  
      window = GTK_WIDGET (gtk_builder_get_object (builder, "window_main"));
  
      gtk_builder_connect_signals (builder, toggle);
      gtk_builder_connect_signals (builder, test);
  
      g_object_unref (builder);
  
      wired (eth0);
      wifi (wlan0);
      gtk_widget_show (window);
  
      gtk_main ();
  
      g_slice_free (net, eth0);
      g_slice_free (net, wlan0);
      g_slice_free (interface, toggle);
  
      return 0;
  
  }
  
  void wifi (net *wlan0) {
  
      if (1) {
          wlan0-&gt;ip_enabled = IPV4_ENABLED;
      }
  
  }
  
  void wired (net *eth0) {
  
      if (1) {
          eth0-&gt;ip_enabled = IPV4_ENABLED;
      }
  
  }
  
  G_MODULE_EXPORT gboolean on_eventbox_image_wired_button_press_event (GtkWidget *widget,
      GdkEvent *event, gpointer toggle) {
  
      if (((interface *) toggle)-&gt;eth0 == NULL) {
          printf("%s\n", "WIRED: eth0 IS NULL - REMOVE ME");
      }
  
      if (((interface *) toggle) == NULL) {
          printf("%s\n", "WIRED: toggle IS NULL - REMOVE ME");
      }
  
      if (((interface *) toggle)-&gt;eth0-&gt;ip_enabled) {
          printf("%s\n", "WIRED: eth0 is ip enabled - REMOVE ME");
          ((interface *) toggle)-&gt;type = IT_ETH0;
          if (((interface *) toggle)-&gt;wlan0-&gt;ip_enabled) {
              printf("%s\n", "WIRED: wlan0 is ip enabled, adjust - REMOVE ME");
          }
  
      }
      return 0;
  }
  
  G_MODULE_EXPORT gboolean on_eventbox_image_wifi_button_press_event (GtkWidget *widget,
      GdkEvent *event, gpointer toggle) {
  
      /* Check to see if we have IP address so we can change the colour otherwise leave it red */
      if (((interface *) toggle)-&gt;wlan0-&gt;ip_enabled) {
          printf("%s\n", "WLAN has IP enabled");
          ((interface *) toggle)-&gt;type = IT_ETH0;
          if (((interface *) toggle)-&gt;eth0-&gt;ip_enabled) {
              printf("%s\n", "WLAN: eth0 is ip enabled, adjust - REMOVE ME");
          }
  
      }
  
      return 0;       
  }
  
  G_MODULE_EXPORT gboolean on_switch_test_on_state_set (GtkSwitch *widget,
      gboolean state, gpointer test) {
  
      (((test_parameters *) test)-&gt;active) = state;
  
      fprintf (stdout, "%s%i\n", "Signal fired and the state is ", state);
  
      return 0;
  
  }
  
  void on_window_main_destroy () {
  
      gtk_main_quit ();
  }
  </code></pre>
  
  <p>And the gdb bt is:</p>
  
  <pre><code>(gdb) run
  Starting program: /home/j2/simplified_example/simplified_example 
  [Thread debugging using libthread_db enabled]
  Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
  [New Thread 0x7fffed0c4700 (LWP 6979)]
  [New Thread 0x7fffec8c3700 (LWP 6980)]
  WIRED: eth0 is ip enabled - REMOVE ME
  WIRED: wlan0 is ip enabled, adjust - REMOVE ME
  Signal fired and the state is 1
  
  Thread 1 "simplified_exam" received signal SIGSEGV, Segmentation fault.
  0x0000000000401110 in on_eventbox_image_wired_button_press_event (widget=0x6a7260 [GtkEventBox], event=0x994cb0, toggle=0x624800)
      at src/simplified_example1.c:134
  134     if (((interface *) toggle)-&gt;eth0-&gt;ip_enabled) {
  (gdb) bt
  #0  0x0000000000401110 in on_eventbox_image_wired_button_press_event (widget=0x6a7260 [GtkEventBox], event=0x994cb0, toggle=0x624800)
      at src/simplified_example1.c:134
  #5  0x00007ffff728008f in &lt;emit signal ??? on instance 0x6a7260 [GtkEventBox]&gt; (instance=instance@entry=0x6a7260, signal_id=&lt;optimised out&gt;, detail=detail@entry=0) at /build/glib2.0-prJhLS/glib2.0-2.48.2/./gobject/gsignal.c:3441
      #1  0x00007ffff76bafac in _gtk_marshal_BOOLEAN__BOXED (closure=0x6ffe50, return_value=0x7fffffffd940, n_param_values=&lt;optimised out&gt;, param_values=0x7fffffffd9a0, invocation_hint=&lt;optimised out&gt;, marshal_data=&lt;optimised out&gt;) at /build/gtk+3.0-2Ut_nl/gtk+3.0-3.18.9/./gtk/gtkmarshalers.c:86
      #2  0x00007ffff7264fa5 in g_closure_invoke (closure=0x6ffe50, return_value=return_value@entry=0x7fffffffd940, n_param_values=2, param_values=param_values@entry=0x7fffffffd9a0, invocation_hint=invocation_hint@entry=0x7fffffffd920) at /build/glib2.0-prJhLS/glib2.0-2.48.2/./gobject/gclosure.c:804
      #3  0x00007ffff7276fc1 in signal_emit_unlocked_R (node=node@entry=0x653b40, detail=detail@entry=0, instance=instance@entry=0x6a7260, emission_return=emission_return@entry=0x7fffffffdab0, instance_and_params=instance_and_params@entry=0x7fffffffd9a0)
      at /build/glib2.0-prJhLS/glib2.0-2.48.2/./gobject/gsignal.c:3629
      #4  0x00007ffff727f7f9 in g_signal_emit_valist (instance=&lt;optimised out&gt;, signal_id=&lt;optimised out&gt;, detail=&lt;optimised out&gt;, var_args=var_args@entry=0x7fffffffdb60) at /build/glib2.0-prJhLS/glib2.0-2.48.2/./gobject/gsignal.c:3395
  #6  0x00007ffff77f8c3c in gtk_widget_event_internal (widget=0x6a7260 [GtkEventBox], event=0x994cb0)
      at /build/gtk+3.0-2Ut_nl/gtk+3.0-3.18.9/./gtk/gtkwidget.c:7692
  #7  0x00007ffff76b83be in propagate_event (topmost=&lt;optimised out&gt;, event=&lt;optimised out&gt;, widget=0x6a7260 [GtkEventBox])
      at /build/gtk+3.0-2Ut_nl/gtk+3.0-3.18.9/./gtk/gtkmain.c:2527
  #8  0x00007ffff76b83be in propagate_event (widget=&lt;optimised out&gt;, event=0x994cb0, captured=&lt;optimised out&gt;, topmost=0x0)
      at /build/gtk+3.0-2Ut_nl/gtk+3.0-3.18.9/./gtk/gtkmain.c:2629
  #9  0x00007ffff76ba1bc in gtk_main_do_event (event=0x994cb0) at /build/gtk+3.0-2Ut_nl/gtk+3.0-3.18.9/./gtk/gtkmain.c:1850
  #10 0x00007ffff66dcd92 in gdk_event_source_dispatch (source=&lt;optimised out&gt;, callback=&lt;optimised out&gt;, user_data=&lt;optimised out&gt;)
      at /build/gtk+3.0-2Ut_nl/gtk+3.0-3.18.9/./gdk/x11/gdkeventsource.c:369
  #11 0x00007ffff6f8e197 in g_main_context_dispatch (context=0x640980) at /build/glib2.0-prJhLS/glib2.0-2.48.2/./glib/gmain.c:3154
  ---Type &lt;return&gt; to continue, or q &lt;return&gt; to quit---
  #12 0x00007ffff6f8e197 in g_main_context_dispatch (context=context@entry=0x640980) at /build/glib2.0-prJhLS/glib2.0-2.48.2/./glib/gmain.c:3769
  #13 0x00007ffff6f8e3f0 in g_main_context_iterate (context=0x640980, block=block@entry=1, dispatch=dispatch@entry=1, self=&lt;optimised out&gt;)
      at /build/glib2.0-prJhLS/glib2.0-2.48.2/./glib/gmain.c:3840
  #14 0x00007ffff6f8e712 in g_main_loop_run (loop=0x8d14b0) at /build/glib2.0-prJhLS/glib2.0-2.48.2/./glib/gmain.c:4034
  #15 0x00007ffff76b9395 in gtk_main () at /build/gtk+3.0-2Ut_nl/gtk+3.0-3.18.9/./gtk/gtkmain.c:1241
  #16 0x0000000000401065 in main (argc=1, argv=0x7fffffffdfd8) at src/simplified_example1.c:97
  (gdb) 
  (gdb) 
  (gdb) 
  </code></pre>
  
  <p>Please and thank you in advance for any assistance on this.</p>
  
  <p>Edit: Added the glade file as requested - it is simplified for testing purposes:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!-- Generated with glade 3.18.3 --&gt;
  &lt;interface&gt;
    &lt;requires lib="gtk+" version="3.12"/&gt;
    &lt;object class="GtkWindow" id="window_main"&gt;
      &lt;property name="can_focus"&gt;False&lt;/property&gt;
      &lt;property name="title" translatable="yes"&gt;Main Window&lt;/property&gt;
      &lt;property name="default_width"&gt;640&lt;/property&gt;
      &lt;property name="default_height"&gt;480&lt;/property&gt;
      &lt;property name="decorated"&gt;False&lt;/property&gt;
      &lt;signal name="destroy" handler="on_window_main_destroy" swapped="no"/&gt;
      &lt;child&gt;
        &lt;object class="GtkFixed" id="fixed_background"&gt;
          &lt;property name="visible"&gt;True&lt;/property&gt;
          &lt;property name="can_focus"&gt;False&lt;/property&gt;
          &lt;child&gt;
            &lt;object class="GtkImage" id="image_background"&gt;
              &lt;property name="name"&gt;4&lt;/property&gt;
              &lt;property name="width_request"&gt;640&lt;/property&gt;
              &lt;property name="height_request"&gt;480&lt;/property&gt;
              &lt;property name="visible"&gt;True&lt;/property&gt;
              &lt;property name="can_focus"&gt;False&lt;/property&gt;
              &lt;property name="stock"&gt;gtk-missing-image&lt;/property&gt;
            &lt;/object&gt;
          &lt;/child&gt;
          &lt;child&gt;
            &lt;object class="GtkEventBox" id="eventbox_image_wired"&gt;
              &lt;property name="width_request"&gt;100&lt;/property&gt;
              &lt;property name="height_request"&gt;80&lt;/property&gt;
              &lt;property name="visible"&gt;True&lt;/property&gt;
              &lt;property name="can_focus"&gt;False&lt;/property&gt;
              &lt;property name="visible_window"&gt;False&lt;/property&gt;
              &lt;property name="above_child"&gt;True&lt;/property&gt;
              &lt;signal name="button-press-event" handler="on_eventbox_image_wired_button_press_event" swapped="no"/&gt;
              &lt;child&gt;
                &lt;object class="GtkImage" id="image_wired"&gt;
                  &lt;property name="width_request"&gt;100&lt;/property&gt;
                  &lt;property name="height_request"&gt;80&lt;/property&gt;
                  &lt;property name="visible"&gt;True&lt;/property&gt;
                  &lt;property name="can_focus"&gt;False&lt;/property&gt;
                  &lt;property name="xalign"&gt;0&lt;/property&gt;
                  &lt;property name="yalign"&gt;0&lt;/property&gt;
                  &lt;property name="icon_name"&gt;applications-graphics&lt;/property&gt;
                &lt;/object&gt;
              &lt;/child&gt;
            &lt;/object&gt;
            &lt;packing&gt;
              &lt;property name="x"&gt;35&lt;/property&gt;
              &lt;property name="y"&gt;20&lt;/property&gt;
            &lt;/packing&gt;
          &lt;/child&gt;
          &lt;child&gt;
            &lt;object class="GtkEventBox" id="eventbox_image_wifi"&gt;
              &lt;property name="width_request"&gt;100&lt;/property&gt;
              &lt;property name="height_request"&gt;80&lt;/property&gt;
              &lt;property name="visible"&gt;True&lt;/property&gt;
              &lt;property name="can_focus"&gt;False&lt;/property&gt;
              &lt;property name="visible_window"&gt;False&lt;/property&gt;
              &lt;property name="above_child"&gt;True&lt;/property&gt;
              &lt;signal name="button-press-event" handler="on_eventbox_image_wifi_button_press_event" swapped="no"/&gt;
              &lt;child&gt;
                &lt;object class="GtkImage" id="image_wifi"&gt;
                  &lt;property name="width_request"&gt;101&lt;/property&gt;
                  &lt;property name="height_request"&gt;71&lt;/property&gt;
                  &lt;property name="visible"&gt;True&lt;/property&gt;
                  &lt;property name="can_focus"&gt;False&lt;/property&gt;
                  &lt;property name="xalign"&gt;0&lt;/property&gt;
                  &lt;property name="yalign"&gt;0&lt;/property&gt;
                  &lt;property name="icon_name"&gt;accessories-text-editor&lt;/property&gt;
                &lt;/object&gt;
              &lt;/child&gt;
            &lt;/object&gt;
            &lt;packing&gt;
              &lt;property name="x"&gt;200&lt;/property&gt;
              &lt;property name="y"&gt;20&lt;/property&gt;
            &lt;/packing&gt;
          &lt;/child&gt;
          &lt;child&gt;
            &lt;object class="GtkGrid" id="grid_test_parameter"&gt;
              &lt;property name="width_request"&gt;582&lt;/property&gt;
              &lt;property name="height_request"&gt;116&lt;/property&gt;
              &lt;property name="visible"&gt;True&lt;/property&gt;
              &lt;property name="can_focus"&gt;False&lt;/property&gt;
              &lt;property name="row_spacing"&gt;10&lt;/property&gt;
              &lt;property name="column_spacing"&gt;4&lt;/property&gt;
              &lt;child&gt;
                &lt;object class="GtkSwitch" id="switch_test_on"&gt;
                  &lt;property name="use_action_appearance"&gt;True&lt;/property&gt;
                  &lt;property name="visible"&gt;True&lt;/property&gt;
                  &lt;property name="can_focus"&gt;True&lt;/property&gt;
                  &lt;signal name="state-set" handler="on_switch_test_on_state_set" swapped="no"/&gt;
                &lt;/object&gt;
                &lt;packing&gt;
                  &lt;property name="left_attach"&gt;0&lt;/property&gt;
                  &lt;property name="top_attach"&gt;0&lt;/property&gt;
                &lt;/packing&gt;
              &lt;/child&gt;
            &lt;/object&gt;
            &lt;packing&gt;
              &lt;property name="x"&gt;15&lt;/property&gt;
              &lt;property name="y"&gt;245&lt;/property&gt;
            &lt;/packing&gt;
          &lt;/child&gt;
        &lt;/object&gt;
      &lt;/child&gt;
    &lt;/object&gt;
  &lt;/interface&gt;
  </code></pre>