0

I have in .c file function to create status_icon object:

file.c

void create_status_icon(GtkWidget *app)
{
    GdkPixbuf *pixbuf;
    GtkIconTheme *icontheme;

    icontheme = gtk_icon_theme_get_default();
    pixbuf = gtk_icon_theme_load_icon(icontheme, "application", 22, 0, NULL);
    g_return_if_fail(pixbuf);
    status_icon = G_OBJECT(gtk_status_icon_new_from_pixbuf(pixbuf)); // <-- uninitialized
    g_object_unref(pixbuf);

    g_signal_connect(G_OBJECT(tray_icon), "activate", G_CALLBACK(tray_activate_cb), (gpointer)app);
    g_signal_connect(G_OBJECT(tray_icon), "popup-menu", G_CALLBACK(tray_popup_menu), (gpointer)app);
}

and put them in .h file

file.h

GObject *status_icon;

void create_status_icon(GtkWidget *app);

I want to use status_icon in others .c files and main but valgrind complain that is Conditional jump or move depends on uninitialised value(s).

main.c

GtkWidget *app;

int main(int argc, char* argv[])

gtk_init(&argc, &argv);

app = application_gui();

/* Create an tray icon */
create_status_icon(app) // <-- uninitialized

How to prevent this?

Thanks

UPDATE valgrind output:

==15658== Conditional jump or move depends on uninitialised value(s)
==15658==    at 0x1929FF17: ??? (in /usr/lib/x86_64-linux-gnu/librsvg-2.so.2.36.4)
==15658==    by 0x192A0AE7: rsvg_handle_get_pixbuf_sub (in /usr/lib/x86_64-linux-gnu/librsvg-2.so.2.36.4)
==15658==    by 0x19074E45: ??? (in /usr/lib/x86_64-linux-gnu/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.so)
==15658==    by 0x6252E8C: gdk_pixbuf_loader_close (in /usr/lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0.2800.1)
==15658==    by 0x624F064: ??? (in /usr/lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0.2800.1)
==15658==    by 0x6250D3C: gdk_pixbuf_new_from_stream_at_scale (in /usr/lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0.2800.1)
==15658==    by 0x56D2528: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.800.2)
==15658==    by 0x56D5941: gtk_icon_info_load_icon (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.800.2)
==15658==    by 0x56D61A2: gtk_icon_info_load_symbolic_for_context (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.800.2)
==15658==    by 0x56D04BF: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.800.2)
==15658==    by 0x56D076C: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.800.2)
==15658==    by 0x56E1C01: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-3.so.0.800.2)
user1840007
  • 615
  • 1
  • 10
  • 19
  • And how is `app` initialized? – Adam Siemion Jul 08 '13 at 23:54
  • As shown this wont even compile - let alone make it as far as valgrind. There is no `app` available to main the only mention of it is as a parameter name. – John3136 Jul 08 '13 at 23:56
  • 2
    In header files, variables should be declared with `extern` (as in `extern GObject *status_icon;`) with almost no exceptions. You then need to provide a source file that defines (and initializes) the variable. However, that is probably tangential to your problem with `app` and/or `pixbuf`. – Jonathan Leffler Jul 09 '13 at 00:07
  • 1
    It looks like valgrind is complaining about stuff deep in the bowels of Gtk+. – asveikau Jul 09 '13 at 00:24
  • You need to run `valgrind` with options to increase the stack depth so that you see your own code in the stack trace. See `valgrind --help` and set `--num-callers=` with a number larger than the default of 12. If your own code is not compiled with `-g`, do so. If it appears that the problems really are in `libgtk` itself, you'll really want a debug build of `libgtk`. – Jonathan Leffler Jul 09 '13 at 01:15

1 Answers1

1

When you declare a variable in a .h file, you must use the extern keyword. There must also be a cooresponding variable definition in a .c file without extern.

With that said, such global variables are strongly discouraged unless you know exactly what you are doing.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • If the definition were missing then it wouldn't link and there would be no executable. A runtime jump depending on an uninitialized value is unrelated to a missing definition at compile time. –  Jul 09 '13 at 00:40
  • @wilsonmichaelpatrick I posted this answer based on an assumption about the error before the OP posted the error message. – Code-Apprentice Jul 09 '13 at 00:44
  • @wilsonmichaelpatrick The definition isn't missing, it's in the OP's header file ... where it doesn't belong as this points out. That the OP's edited submission has some muddle and confusion about the error encountered and what caused it is a different matter. – Jim Balter Jul 09 '13 at 01:54