Re: [gtk-list] Re: Leak in g_print(), g_strdup_vprintf()



Tim Janik wrote:

> #include <glib.h>
> #include <unistd.h>
> 
> int
> main ()
> {
>   gpointer *last = NULL;
> 
>   g_print ("pid: %d\n", getpid ());
> 
>   while (1)
>     {
>       gpointer new = g_strdup_printf ("test %d %s %f\n", 5, "huhu", 6.0);
>       g_free (last);
>       last = new;
>     }
>   return 0;
> }
> 
> i didn't see any program size increses over 10 minutes.
> the last line of the g_print implementation g_free()s the string
> returned from g_strdup_vprintf() thus it's not leaking
> either. apart from that, i just reviewed the code implementing
> g_strdup_vprintf() and couldn't find any leaks at all.
> so in order for g_strdup_vprintf() to leak on your system, you are
> either not freeing the string it returns or your system's
> implementation of vsprintf() is leaking (very unlikely).

I haven't tested that program, but one very similar to it leaked on my
home machine.  I reviewed the code too, and couldn't see anything that
would cause it to leak, but it did nevertheless.  I'm wondering whether
there's a bug in vararg handling somewhere: it's the only thing that
seems at all unusual, but surely copying va_arg pointers shouldn't cause
any problems?  I'll have a look again tonight.

-- 
 /\\\  Mincom | Martin Pool          | martinp@mincom.com
// \\\        | Software Engineer    | Phone: +61 7 3303-3333
\\ ///        | Mincom Pty. Ltd.     | 
 \///         | Teneriffe, Brisbane  | Speaking for myself only



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