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



On Tue, 20 Apr 1999, Martin Pool wrote:

> There seems to be a serious memory leak in these functions in glib-1.2.1
> under RedHat ~5.2/x86.  Repeated calls to g_print ("%s", "hello\n")
> cause a linear increase in DSIZ.
> 
> I have some debugging information at home, but thought I'd check whether
> anybody else knew of it before continuing to trace it.

g_strdup_printf() is a simply var args wrapper around g_strdup_vprintf()
and with

#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).


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

---
ciaoTJ



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