Thread: gtk+ structure member problem
hello,
having trouble setting gchar *filename gchar *file_name gchar *file_name member of structure fileinfo , struct fileinfo nested struct of publicdata. here code:
code:structure window.h typedef struct { gboolean file_flag; gchar *file_name; }fileinfo; signals.c void save_file_as(gtkbutton *save, mainwin *mw, fileinfo *fi) { gtkwidget *dialog; gtktextiter start, end; gchar *filename, *content; gint result; dialog = gtk_file_chooser_dialog_new("save as...", null, gtk_file_chooser_action_save, gtk_stock_ok, gtk_response_accept, gtk_stock_cancel, gtk_response_cancel, null); result = gtk_dialog_run(gtk_dialog(dialog)); if(result == gtk_response_accept) { filename = gtk_file_chooser_get_filename(gtk_file_chooser(dialog)); gtk_text_buffer_get_bounds(mw->buffer, &start, &end); content = gtk_text_buffer_get_text(mw->buffer, &start, &end, false); g_file_set_contents(filename, content, -1, null); fi->file_flag = true; fi->file_name = filename; g_free(filename); g_free(content); } gtk_widget_destroy(dialog); }
here output when hit save button.
if print filename screen, path file. have fi->file_name set null. when try print fi->file_name screen, segmentation fault. not sure going on fi->file_name.code:(codepad2:10842): glib-gobject-critical **: g_object_unref: assertion `g_is_object (object)' failed (codepad2:10842): glib-gobject-critical **: g_object_ref: assertion `g_is_object (object)' failed (codepad2:10842): glib-gobject-critical **: g_object_unref: assertion `g_is_object (object)' failed (codepad2:10842): glib-gobject-critical **: g_object_get_qdata: assertion `g_is_object (object)' failed segmentation fault
here copy filename pointer fi->file_name pointer , deleting content filename (and fi->file_name) points to.code:fi->file_name = filename; g_free(filename);
result both pointers invalid.
next thing tries dereference fi->file_name or filename produce segfault
use g_strdup allocate copy of filename , assign fi->file_name
(or don't free filename in first place if thats ok in application)
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk gtk+ structure member problem
Ubuntu
Comments
Post a Comment