Re: Bug in GLib, libglade, libc??



Hi,

First of all, this should really be better documented elsewhere, but
valgrind has some problems debugging and profiling multithreaded code
(such as Gtk/Glib). To get some more accurate results, try the
following:

G_SLICE=always-malloc G_DEBUG=gc-friendly valgrind -v --show-reachable "myapp"

Some more of these environment variables are documented here:
http://developer.gnome.org/doc/API/2.0/glib/glib-running.html

Also, if you're using lists and strings and such, you might want to
use the GLib API's instead of hand-rolling your own. Things such as
GSList, GList, and GString can make your life a lot easier, depending
on what you're doing.

Finally, you shouldn't be using g_free on GObjects (such as GtkWidgets
and *I think* the GladeXML). Rather, use gtk_widget_destroy or
g_object_unref. GLib uses reference counting so that you don't have to
worry too much about memory management.

If trying these things doesn't work, you can always post the code ;-)

Cheers,
Samuel

On 8/14/06, Fabricio Rocha <rocha_fabricio yahoo com br> wrote:
Thank you very much, Yeti and Samuel, for your replies!

        I really believe that there is something wrong in MY code, and not in
libglade, nor libc, nor GTK, etc., that makes my program react so
different every time I compile and run it. However, I still could not
figure what exactly is wrong.

        I have a suspicion from my lack of practice in C: a module of my
program uses a structured type which must contain, as its last member, a
dynamic list of strings, i.e., pointers to gchars (**list). Sometimes I
need to fill only the first string, and sometimes I will need more than
one string. So I suspect that each attempt to set a value for one of
these pointers cause a serious corruption of other areas of the program,
like the GTK stuff in memory. I have tried to assign values to this
(these) pointers both with g_strdup and by creating a local, initialized
array and assigning its address to the pointer. Neither worked. Do you
think I should give each pointer a malloc'd space somewhere in memory,
and then strcpy the value to this pointer?

        By the way, I have read a lot of GDB and Valgrind docs, and still could
not get anything from them. My application is one of those standard
libglade apps with a main() function that only loads a main window from
the XML and show it, and I really don´t understand some things from
Valgrind:

        - "Conditional jump or move depends on uninitialised values", which is
by itself not so bad, according to Valgrind docs;

        - "Syscall param write (buf) points to uninitialised byte(s)" in the
lines which calls gtk_init(&argc, &argv) and gtk_init(); which, if I am
right, is normal as there is nothing passed to the application in the
command line;

        - Various "Invalid read of size 4 (...) Address 0xxxxx is 24 bytes
inside a block of size 25 alloc´d" caused by the line with
"glade_xml_signal_autoconnect". Hey, what is wrong if an address is
WITHIN the alloc´d block?? And look that, until now, there is *not* code
of "myself", it is just what every libglade example tells!

        - "Invalid free() / delete / delete[]" in the lines right after
gtk_main(), where I try to g_free both the pointers to the loaded XML
file and the main window widget. I have set breakpoints in GDB right
before these lines and they HAD non-NULL values until here...

        - The program finishes with surprising 141kB "possibly lost" and 931kB
(!) "still reachable" memory leaks. I can´t figure out what exactly is
causing such a memory waste -- the only thing the program does until now
is loading and closing the main window and a dialog window! In
GTK/libglade programming, could you point out which are the most common
"to-check" things to avoid that?

        Please, sorry for such a big post, but I hope you understand that, as
Yeti said, I am really *trying* to debug the thing by myself, instead of
just coming here and shout.... but until now I couldn´t really find any
big clue with GDB, and, although Valgrind is really impressive, it does
not tell much about *what* to do for newbies like me -- as a friend
said, it is like going to a physician who says "hmm, it looks like you
have fluid in your left lung", but does not tell you how it happened and
what to do then...

Thank you again and best regards to all!

Fabricio Rocha
Brasilia, Brasil




_______________________________________________________
O Yahoo! está de cara nova. Venha conferir!
http://br.yahoo.com





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]