GNOME Bugzilla – Bug 302696
Segfault and cheep mend of gtk_combo_box_get_active_text
Last modified: 2011-02-04 16:18:28 UTC
Steps to reproduce: 1. Minimal C-program essai.c included below. 2. Compile it with gcc -Wall -pedantic essai.c -o essai.o -lm `pkg-config --cflags --libs gtk+-2.0` 3. Run it with ./essai.o 4. When changing the string in the combo box, it crashes. Stack trace: With gdb ./essai.o : ------------------------------------------------------------------ (gdb) run Starting program: /home/ramare/tex/Sol/c/essai.o [Thread debugging using libthread_db enabled] [New Thread 1082006784 (LWP 9437)] Detaching after fork from child process 9440. Detaching after fork from child process 9441. line 20 line 22 Program received signal SIGSEGV, Segmentation fault.
+ Trace 59031
Thread 1082006784 (LWP 9437)
-------------------------------------------------- Program essai.c : -------------------------------------------------- #include <stdlib.h> #include <stdio.h> #include <string.h> #include <gtk/gtk.h> GtkWidget *window, *my_combo_box; void my_gtk_widget_destroy(GtkWidget *widget) { gtk_widget_destroy(widget); gtk_main_quit(); } void selecter(GtkComboBox *combo, gpointer user_data) { gchar *name; if (user_data != NULL){printf("What ???");}; if (combo != GTK_COMBO_BOX(my_combo_box)) printf("not initialized!!!\n"); printf("line %d\n", __LINE__); if (combo != NULL) { printf("line %d\n", __LINE__); name = gtk_combo_box_get_active_text(GTK_COMBO_BOX(combo)); printf("line %d\n", __LINE__); if (name == NULL) { printf("line %d\n", __LINE__); printf("What are we doing in here ???"); printf("line %d\n", __LINE__); } else { printf("line %d\n", __LINE__); printf("Ok %s \n", name); printf("line %d\n", __LINE__); }; }; } int main(int argc, char *argv[]) { gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(my_gtk_widget_destroy), NULL); my_combo_box = gtk_combo_box_new_text(); gtk_combo_box_append_text(GTK_COMBO_BOX(my_combo_box), "Oui"); gtk_combo_box_append_text(GTK_COMBO_BOX(my_combo_box), "Non"); /*gtk_combo_box_set_active(GTK_COMBO_BOX (my_combo_box),0); gtk_combo_box_set_active(GTK_COMBO_BOX (my_combo_box),1);*/ g_signal_connect (G_OBJECT(my_combo_box), "changed", G_CALLBACK (selecter), NULL); gtk_container_add(GTK_CONTAINER(window), my_combo_box); gtk_widget_show_all(window); gtk_main(); return 0; } -------------------------------------------------------------- Other information: 5. If I replace gtk_combo_box_get_active_text with gchar * my_gtk_combo_box_get_active_text (GtkComboBox *combo_box) { /* gtk_combo_box_get_active_text goes to segfault here ... This one doesn't */ GtkTreeIter iter; gchar *text = NULL; GtkTreeModel* model = gtk_combo_box_get_model(combo_box); if (gtk_combo_box_get_active_iter (combo_box, &iter)) gtk_tree_model_get (model, &iter, 0, &text, -1); return text; } the bug disappears. 6. Suse 9.1 pro with pango 1.8.1 in /opt/gnome/share/pango-1.8.1/ atk 1.9.0 in /opt/gnome/share/atk-1.9.0/ gtk+ 2.6.7 in /opt/gnome/share/gtk+-2.6.7/ 7. Hope that helps !
1. On a larger program, the proposed mend doesn't work either :-( 2. Several people compiled the essai.c script and found no segfaults. 3. In case, it has to do with Locale, here is France :-)
The testcase works fine for me with both cvs branches. Can you provide a stacktrace from the segfault ?
Script being as above I compiled it with gcc -ggdb -Wall -pedantic essai.c -o essai.o -lm `pkg-config --cflags --libs gtk+-2.0` then run "gdb ./essai.o" and session is as follows : ---------------------------------------------------------------------------- GNU gdb 6.2.1 Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i586-suse-linux"...Using host libthread_db library "/lib/tls/libthread_db.so.1". (gdb) break selecter Breakpoint 1 at 0x804895d: file essai.c, line 16. (gdb) run --sync Starting program: /home/ramare/tex/Sol/c/essai.o --sync [Thread debugging using libthread_db enabled] [New Thread 1082010880 (LWP 5945)] Detaching after fork from child process 5948. Detaching after fork from child process 5949. [Switching to Thread 1082010880 (LWP 5945)] HERE I SELECT "non" Breakpoint 1, selecter (combo=0x8136370, user_data=0x0) at essai.c:16 16 if (user_data != NULL){printf("What ???");}; (gdb) step 17 if (combo != GTK_COMBO_BOX(my_combo_box)) (gdb) IA__g_type_check_instance_cast (type_instance=0x8136370, iface_type=134738592) at gtype.c:3153 3153 if (type_instance) (gdb) 3155 if (type_instance->g_class) (gdb) 318 { (gdb) 319 if (utype > G_TYPE_FUNDAMENTAL_MAX) (gdb) 3161 is_instantiatable = node && node->is_instantiatable; (gdb) 319 if (utype > G_TYPE_FUNDAMENTAL_MAX) (gdb) 3163 check = is_instantiatable && iface && type_node_conforms_to_U (node, iface, TRUE, FALSE); (gdb) 2731 if (/* support_inheritance && */ (gdb) 3182 } (gdb) selecter (combo=0x8136370, user_data=0x0) at essai.c:20 20 printf("line %d\n", __LINE__); (gdb) line 20 21 if (combo != NULL) { (gdb) 22 printf("line %d\n", __LINE__); (gdb) line 22 23 name = gtk_combo_box_get_active_text(GTK_COMBO_BOX(combo)); (gdb) IA__g_type_check_instance_cast (type_instance=0x8136370, iface_type=134738592) at gtype.c:3153 3153 if (type_instance) (gdb) 3155 if (type_instance->g_class) (gdb) 318 { (gdb) 319 if (utype > G_TYPE_FUNDAMENTAL_MAX) (gdb) 3161 is_instantiatable = node && node->is_instantiatable; (gdb) 319 if (utype > G_TYPE_FUNDAMENTAL_MAX) (gdb) 3163 check = is_instantiatable && iface && type_node_conforms_to_U (node, iface, TRUE, FALSE); (gdb) 2731 if (/* support_inheritance && */ (gdb) 3182 } (gdb) Program received signal SIGSEGV, Segmentation fault. 0x00000000 in ?? () (gdb) ----------------------------------------------------------- Nothing more is available. Hope that helps ! Best, Amities, Olivier
No, I can't reproduce.
Please reopen if you can reproduce with 2.6.8