[10278] in The GTK GIMP ToolKit mailing list archive
[gtk-list] Memory leaks in glib from GTK+ 1.0.6
daemon@ATHENA.MIT.EDU (Andreas Tille)
Fri Nov 20 03:06:25 1998
Date: Fri, 20 Nov 1998 09:05:41 +0100 (MET)
From: Andreas Tille <tille@physik.uni-halle.de>
To: GTK User-List <gtk-list@redhat.com>
Resent-From: gtk-list@redhat.com
Reply-To: gtk-list@redhat.com
Hello,
I've detected the reason for three memory leaks in glib from
the GTK+ 1.0.6 distribution. It is the global variable
_GRealListAllocator. Here is a code snipped from glist.c:
...
#include "glib.h"
typedef struct _GRealListAllocator GRealListAllocator;
struct _GRealListAllocator
{
GMemChunk *list_mem_chunk;
GList *free_list;
};
static GRealListAllocator *default_allocator = NULL;
static GRealListAllocator *current_allocator = NULL;
...
When a g_list is allocated this struct allocates three pointers
which will never be freed and I didn't see any clue, how to do
that, because they are hidden for the application.
Here is a very small program with Makefile which demonstrates the
problem:
------------------------------------------------------------------------
memory_leak.c:
------------------------------------------------------------------------
#include <dmalloc.h>
#include <glib.h>
void main(void)
{
GList *piclist = g_list_append(NULL, "Test");
g_list_free(piclist);
}
------------------------------------------------------------------------
Makefile
------------------------------------------------------------------------
NAME = memory_leak
CFLAGS=-g -D__DMALLOC__ -DDMALLOC_FUNC_CHECK `gtk-config --cflags`
LDFLAGS=-lglib -ldmalloc
$(NAME): $(NAME).o
$(NAME).o: $(NAME).c
------------------------------------------------------------------------
Here are the interesting lines of the output from dmalloc:
3: not freed: '0x804c008|s1' (8 bytes) from 'ra=0x40014246'
3: not freed: '0x804d008|s1' (52 bytes) from 'ra=0x40014246'
3: not freed: '0x804e008|s1' (1024 bytes) from 'ra=0x40014246'
3: unknown memory not freed: 3 pointers, 1084 bytes
I think this should be fixed to have a clean library.
I havn't any idea how it is solved in glib 1.1.4. Possibly someone
can check this.
Kind regards
Andreas.
--
To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null