segmentation fault - segfault in c/gtk+3 program -
structs defined inside header:
struct info{ gint mode, issignalactivate; gchar *filename; gtkwidget *pwdentry, *pwdreentry, *mainwin, *dialog, *file_dialog; }; extern struct info s_info; struct hashes{ gchar *filename; gtkwidget *entrymd5, *entrys1, *entrys256, *entrys512, *entrywhir, *entryrmd; gtkwidget *checkmd5, *checks1, *checks256, *checks512, *checkwhir, *checkrmd; }; extern struct hashes s_hashtype;
and main part of program:
int main(int argc, char **argv){ if(!gcry_check_version(gcrypt_min_ver)){ fputs("libgcrypt min version required: 1.5.0\n", stderr); return -1; } gcry_control(gcryctl_init_secmem, 16384, 0); gcry_control(gcryctl_initialization_finished, 0); gtkapplication *app; int status; app = gtk_application_new ("org.gtk.polcrypt",g_application_flags_none); g_signal_connect (app, "startup", g_callback (startup), null); g_signal_connect (app, "activate", g_callback (activate), null); status = g_application_run (g_application (app), argc, argv); g_object_unref (app); return status; } static void startup (gtkapplication *application, gpointer user_data __attribute__ ((unused))) { static const gactionentry actions[] = { { "about", }, { "quit", quit } }; gmenu *menu; g_action_map_add_action_entries (g_action_map (application), actions, g_n_elements (actions), application); menu = g_menu_new (); g_menu_append (menu, "about", "app.about"); g_menu_append (menu, "quit", "app.quit"); gtk_application_set_app_menu (application, g_menu_model (menu)); g_object_unref (menu); } static void activate (gtkapplication *app, gpointer user_data __attribute__ ((unused))) { gtkwidget *butha, *grid; struct info s_info; s_info.mainwin = gtk_application_window_new(app); gtk_window_set_application (gtk_window (s_info.mainwin), gtk_application (app)); gtk_window_set_position(gtk_window(s_info.mainwin), gtk_win_pos_center); gtk_window_set_title(gtk_window(s_info.mainwin), "polcrypt"); gtk_window_set_resizable(gtk_window(s_info.mainwin), false); gtk_container_set_border_width(gtk_container(s_info.mainwin), 10); butha = gtk_button_new_with_label("compute hash"); g_signal_connect(butha, "clicked", g_callback (is_hash), &s_info); grid = gtk_grid_new(); gtk_container_add(gtk_container(s_info.mainwin), grid); gtk_grid_set_row_homogeneous(gtk_grid(grid), true); gtk_grid_set_column_homogeneous(gtk_grid(grid), true); gtk_grid_set_row_spacing(gtk_grid(grid), 5); gtk_grid_set_column_spacing(gtk_grid(grid), 5); //numero colonna, numero riga, colonne da occupare, righe da occupare. colonne e righe sono aggiunte automaticamente gtk_grid_attach(gtk_grid(grid), butha, 0, 0, 5, 1); gtk_widget_show_all(s_info.mainwin); } static void is_hash(gtkwidget *ignored __attribute__ ((unused)), struct info *s_info){ s_info->mode = 3; file_dialog(s_info); } static void file_dialog(struct info *s_info){ s_info->file_dialog = gtk_file_chooser_dialog_new("choose file", null, gtk_file_chooser_action_open, ("_cancel"), gtk_response_cancel, ("_ok"), gtk_response_accept, null); if (gtk_dialog_run (gtk_dialog (s_info->file_dialog)) == gtk_response_accept){ s_info->filename = gtk_file_chooser_get_filename (gtk_file_chooser (s_info->file_dialog)); if(s_info->mode == 3){ select_hash_type(s_info); g_free (s_info->filename); } } gtk_widget_destroy (s_info->file_dialog); } static void select_hash_type(struct info *s_infohash){ gtk_widget_hide(gtk_widget(s_infohash->file_dialog)); struct hashes s_hashtype; gtkwidget *content_area, *grid2; s_infohash->dialog = gtk_dialog_new_with_buttons ("select hash", null, gtk_dialog_modal | gtk_dialog_destroy_with_parent, "_quit", gtk_response_close, null); content_area = gtk_dialog_get_content_area (gtk_dialog (s_infohash->dialog)); s_hashtype.checkmd5 = gtk_check_button_new_with_label("md5"); s_hashtype.entrymd5 = gtk_entry_new(); gtk_editable_set_editable(gtk_editable(s_hashtype.entrymd5), false); gtk_widget_set_size_request(s_infohash->dialog, 250, 150); // richiedo una grandezza minima grid2 = gtk_grid_new(); gtk_grid_set_row_homogeneous(gtk_grid(grid2), true); // righe stessa altezza gtk_grid_set_column_homogeneous(gtk_grid(grid2), true); // colonne stessa larghezza gtk_grid_set_row_spacing(gtk_grid(grid2), 5); // spazio fra le righe // numero colonna, numero riga, colonne da occupare, righe da occupare gtk_grid_attach(gtk_grid(grid2), s_hashtype.checkmd5, 0, 0, 1, 1); gtk_grid_attach(gtk_grid(grid2), s_hashtype.entrymd5, 2, 0, 6, 1); /* add grid, , show we've added dialog */ gtk_container_add (gtk_container (content_area), grid2); gtk_widget_show_all (s_infohash->dialog); s_hashtype.filename = malloc(strlen(s_infohash->filename)+1); strcpy(s_hashtype.filename, s_infohash->filename); g_signal_connect_swapped(s_hashtype.checkmd5, "clicked", g_callback(compute_md5), &s_hashtype); gint result = gtk_dialog_run(gtk_dialog(s_infohash->dialog)); switch(result){ case gtk_response_close: gtk_widget_destroy(s_infohash->dialog); break; } free(s_hashtype.filename); }
my problem program segfault when clicking on "quit" button of s_infohash->dialog
.
above there output of gdb.
program received signal sigsegv, segmentation fault. 0x00000000009aa4f0 in ?? () (gdb) #0 0x00000000009aa4f0 in ?? () #1 0x00000000008f2290 in ?? () #2 0x00007fffffffd330 in ?? () #3 0x00000000007e0480 in ?? () #4 0x0000000000000188 in ?? () #5 0x0000000040000002 in ?? () #6 0x00007ffff5afbba9 in g_hash_table_lookup () /usr/lib64/libglib-2.0.so.0 #7 0x00007ffff5e17b7f in g_signal_emit_valist () /usr/lib64/libgobject-2.0.so.0 #8 0x00007ffff5e1881a in g_signal_emit () /usr/lib64/libgobject-2.0.so.0 #9 0x00007ffff76be454 in ?? () /usr/lib64/libgtk-3.so.0 #10 0x00007ffff75943dc in ?? () /usr/lib64/libgtk-3.so.0 #11 0x00007ffff7595c2a in gtk_main_do_event () /usr/lib64/libgtk-3.so.0 #12 0x00007ffff71ac522 in ?? () /usr/lib64/libgdk-3.so.0 #13 0x00007ffff5b0bc66 in g_main_context_dispatch () /usr/lib64/libglib-2.0.so.0 #14 0x00007ffff5b0bfb8 in ?? () /usr/lib64/libglib-2.0.so.0 #15 0x00007ffff5b0c05c in g_main_context_iteration () /usr/lib64/libglib-2.0.so.0 #16 0x00007ffff60d9eec in g_application_run () /usr/lib64/libgio-2.0.so.0 #17 0x0000000000403339 in main (argc=1, argv=0x7fffffffd878) @ src/gtk3/main-gui.c:35
this thing driving me crazy because cannot find causing segfault... (i know gdb gtk_application_run (#17)
mean? how can debug , fix thing?)
i'm using gcc 4.8.1 , gtk+ 3.10
s_info
cease exist after leaving activate()
, whenever signal issued accessing invalid memory chunk (formerly occupied s_info
, pointed &s_info
pass user_data
signal callback)
Comments
Post a Comment