Gtksourceview4 giving me a strange error in valgrind

The code below is giving me some strange errors when run in valgrind:

        GtkWidget * text = gtk_source_view_new();
        gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_NONE);
        gtk_text_view_set_monospace(GTK_TEXT_VIEW(text), TRUE);
        gtk_source_view_set_insert_spaces_instead_of_tabs(GTK_SOURCE_VIEW(text), TRUE);
        gtk_source_view_set_tab_width(GTK_SOURCE_VIEW(text), 4);
        gtk_source_view_set_show_line_numbers(GTK_SOURCE_VIEW(text), TRUE);
        
        main = gtk_scrolled_window_new(NULL, NULL);
        gtk_container_add(GTK_CONTAINER(main), text);

        GtkTextBuffer * buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));

        GtkSourceSearchContext * context = gtk_source_search_context_new(GTK_SOURCE_BUFFER(buffer), NULL);
        GtkSourceLanguageManager * manager = gtk_source_language_manager_get_default();

        GtkSourceLanguage * language = gtk_source_language_manager_guess_language (manager, filename, content_type);

        gtk_source_search_context_set_highlight(context, TRUE);
        gtk_source_buffer_set_language(GTK_SOURCE_BUFFER(buffer), language);
        gtk_source_search_settings_set_wrap_around(gtk_source_search_context_get_settings(context), TRUE);

First off, the code in question appears to run fine when I simply run it, but when I run it in valgrind I am spammed with the “Conditional jump or move depends on uninitialised value” error. At first I thought this might be one of the data structures I have implemented which are being compared, but when I inspected further I found that error is arising from a realloc done by the gtk_source_buffer_set_language call:

==11453== Conditional jump or move depends on uninitialised value(s)
==11453== at 0xD1403C8: ???
==11453== by 0xB0D9CBF: ???
==11453== Uninitialised value was created by a heap allocation
==11453== at 0x4848B80: realloc (vg_replace_malloc.c:1690)
==11453== by 0x57D53D2: g_realloc (gmem.c:201)
==11453== by 0x57F02C2: UnknownInlinedFun (gstring.c:92)
==11453== by 0x57F02C2: g_string_expand (gstring.c:78)
==11453== by 0x57F0330: g_string_sized_new (gstring.c:123)
==11453== by 0x57E87FF: g_regex_replace_eval (gregex.c:3459)
==11453== by 0x48E1244: UnknownInlinedFun (gtksourcelanguage-parser-2.c:1047)
==11453== by 0x48E1244: expand_regex.constprop.0 (gtksourcelanguage-parser-2.c:1190)
==11453== by 0x48DCEB7: UnknownInlinedFun (gtksourcelanguage-parser-2.c:1306)
==11453== by 0x48DCEB7: UnknownInlinedFun (gtksourcelanguage-parser-2.c:1552)
==11453== by 0x48DCEB7: file_parse.lto_priv.0 (gtksourcelanguage-parser-2.c:1682)
==11453== by 0x48DE3A6: UnknownInlinedFun (gtksourcelanguage-parser-2.c:1360)
==11453== by 0x48DE3A6: UnknownInlinedFun (gtksourcelanguage-parser-2.c:1430)
==11453== by 0x48DE3A6: UnknownInlinedFun (gtksourcelanguage-parser-2.c:1532)
==11453== by 0x48DE3A6: UnknownInlinedFun (gtksourcelanguage-parser-2.c:1556)
==11453== by 0x48DE3A6: file_parse.lto_priv.0 (gtksourcelanguage-parser-2.c:1682)
==11453== by 0x48ABC4E: UnknownInlinedFun (gtksourcelanguage-parser-2.c:1820)
==11453== by 0x48ABC4E: gtk_source_language_parse_file.lto_priv.0 (gtksourcelanguage.c:735)
==11453== by 0x4899504: UnknownInlinedFun (gtksourcelanguage.c:762)
==11453== by 0x4899504: gtk_source_buffer_set_language (gtksourcebuffer.c:1832)
==11453== by 0x1121FE: newpage (explorer.c:96)
==11453== by 0x11252D: selected (explorer.c:138)

Does anyone know why I am getting this error? I’ve made sure that the text buffer generated by the source view is indeed a valid source buffer, and I have no idea how to guarantee that the language is valid aside the fact that the code runs when I don’t run with valgrind, only valgrind is giving me this strange error.

Hi,

Just to be sure: have you called gtk_source_init() at the startup of your program?

I had not, but unfortunately this does not fix the issue.

OK.

Can you please give us the exact versions of GtkSourceview, Gtk and GLib?
Do you use Linux, Windows or Mac?

I’m using Arch Linux, and here are the exact library version:
libgtk-3.so.0.2407.32
libglib-2.0.so.0.7800.3
libgtksourceview-4.so.0.0.0

Thanks!
I’ll check if I can reproduce on my side.

I saw the issue too with gtksourceview versions 4 and 5.

Could also be an issue on GLib side.
I’ll have a closer look.

For anyone else attempting to reproduce the bug I have managed to boil down my code to this small snippet that will produce the error in question:

#include <gtksourceview/gtksource.h>
int main () {
    gtk_init(NULL, NULL);
    gtk_source_init();

    GtkWidget * window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);

    GtkWidget * text = gtk_source_view_new();

    GtkTextBuffer * buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
    GtkSourceLanguageManager * manager = gtk_source_language_manager_get_default();

    GtkSourceLanguage * language = gtk_source_language_manager_guess_language (manager, "../file.c", NULL);
    gtk_source_buffer_set_language(GTK_SOURCE_BUFFER(buffer), language);

    gtk_container_add(GTK_CONTAINER(window), text);

    gtk_widget_show_all(window);
    gtk_main();

    gtk_source_finalize();
    return 0;
}

Compile with:

gcc main.c pkg-config --cflags --libs gtksourceview-4

Debug with:

valgrind --suppressions=/usr/share/glib-2.0/valgrind/glib.supp --suppressions=/usr/share/gtk-3.0/valgrind/gtk.supp --track-origins=yes ./a.out

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