title: Why do I get a segmentation fault in my GTK+ signal callback?
body: <p>I am trying to measure the size of a GTK label:</p>
  
  <pre><code>#include &lt;gtk/gtk.h&gt;
  
  static void map_event(GtkWidget *window, gpointer lab) {
      g_print( "In the callback..\n" );
      GtkWidget *label = GTK_WIDGET(lab);
      g_print( "Everything is ok..\n" );
  }
  
  static void activate (GtkApplication* app, gpointer user_data)
  {
      GtkWidget *window = gtk_application_window_new (app);
      gtk_window_set_title (GTK_WINDOW (window), "Window1");
      gtk_window_set_default_size (GTK_WINDOW (window), 200, 280);
      GtkWidget *grid = gtk_grid_new ();
      gtk_container_add (GTK_CONTAINER (window), grid);
      GtkWidget *label = gtk_label_new("Hello world!");
      gtk_grid_attach(GTK_GRID (grid), label, 0,0,1,1);
      g_signal_connect (window, "map-event", G_CALLBACK(map_event), label);
      gtk_widget_show_all (window);
  }
  
  int main (int argc, char **argv) {
      GtkApplication *app = gtk_application_new (
          "org.gtk.example", G_APPLICATION_FLAGS_NONE );
      g_signal_connect( app, "activate", G_CALLBACK(activate), NULL);
      int status = g_application_run(G_APPLICATION(app), argc, argv);
      g_object_unref (app);
  
      return status;
  }
  </code></pre>
  
  <p>This gives output:</p>
  
  <pre><code>In the callback..
  Segmentation fault (core dumped)
  </code></pre>
  
  <p>If I comment out the line:</p>
  
  <pre><code>GtkWidget *label = GTK_WIDGET(lab);
  </code></pre>
  
  <p>there is no segmentation fault, the label shows up and the output is:</p>
  
  <pre><code>In the callback..
  Everything is ok..
  </code></pre>
  
  <p>What am I missing here?</p>