Segmentation fault (core dumped)

Can someone help me with a problem I’m having.
I don’t understand why the error.

I have a GtkListBoxRow with two GtkLabel.
I get the text from GtkLabel at GtkListBoxRow.
I pass the obtained text to another GtkLabel that is in a GtkBox.
The destroy the GtkListBoxRow the program closes with the error:
Segmentation fault (core dumped)

Thank you guys.

I asked a similar question here, it might help. Why "segmentation fault" arises and how to avoid it?

1 Like

Hey @galetedanilo, according to the docs, gtk_label_get_label

the text of the label widget. This string is owned by the widget and must not be modified or freed.

I suspect what happens is that, when you destroy GtkListBoxRow, you are also destroying the text you are referencing from your other GtkLabel.

You just need to copy the string, before passing it to the other GtkLabel.

I should just use g_stpcpy?

g_strdup should be a tad simpler

1 Like

Does not work:
This is the code

struct _MyListBoxRow{
GtkListBoxRow parent;`

GtkLabel *label_name;

const gchar*
my_func_get_label_name (MyListBoxRow *self)
const gchar *name;

name = gtk_label_get_text (GTK_LABEL (self->label_name));

return name;


gtk_label_set_text (GTK_LABEL (other_label), my_func_get_label_name (my_list_box));

Note that you are not copying the label text, you are still passing around the reference owned by the label.

However this shouldn’t be the issue at hand: It’s true that gtk_label_get_text() keeps ownership of the string, but gtk_label_set_text() copies the passed string rather than taking ownership of it.

I recommend you run your program in gdb to get a backtrace instead of trying to guess the cause.

1 Like

Thank you for the advice.
I check in my code that after deleting the GtkListBoxRow it was destroyed, the row-selected signal was emitted again and a null pointer was passed to the function. With this the error occurred.
I am implementing a financial control program in c, and use as a base the Gnome Contacts designer, I already implemented the side panel, the one with the names and a round label, and the error occurred when I selected an item in the GtkListBox and clicked the delete button. Now it works before trying to delete I check if the point is null, I don’t know if this is the correct way but it worked.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.