Re: [gtk-list] Memchunks again
- From: Soeren Sandmann <sandmann daimi au dk>
- To: gtk-devel-list redhat com
- Subject: Re: [gtk-list] Memchunks again
- Date: 17 Aug 1999 11:47:03 +0200
Soeren Sandmann <sandmann@daimi.au.dk> writes:
> The following code segfaults. Do you have any idea why? The seqfault
> seems to go away if SIZE is less than 65513. It also goes away if
> G_ALLOC_ONLY is changed into G_ALLOC_AND_FREE.
>
> #include <glib.h>
>
> #define SIZE 65513
>
> int
> main ()
> {
> GMemChunk *chunk;
> guint8 *t1, *t2;
> gint i;
>
> chunk = g_mem_chunk_create (guint8[SIZE], 4, G_ALLOC_ONLY);
>
> t1 = g_chunk_new (guint8, chunk);
> for (i=0; i<SIZE; i++)
> t1[i] = 'a';
> t2 = g_chunk_new (guint8, chunk);
> }
I think it is a bug in GLib because GMemChunk->area_size in certain
cases can be smaller than the atom_size. I think the following patch
fixes it:
RCS file: /cvs/gnome/glib/gmem.c,v
retrieving revision 1.15
diff -u -r1.15 gmem.c
--- glib/gmem.c 1999/07/24 18:50:55 1.15
+++ glib/gmem.c 1999/08/17 09:42:28
@@ -492,13 +492,13 @@
mem_chunk->area_size = area_size;
if (mem_chunk->area_size > MAX_MEM_AREA)
mem_chunk->area_size = MAX_MEM_AREA;
- while (mem_chunk->area_size < mem_chunk->atom_size)
- mem_chunk->area_size *= 2;
rarea_size = mem_chunk->area_size + sizeof (GMemArea) - MEM_AREA_SIZE;
rarea_size = g_mem_chunk_compute_size (rarea_size);
+ while (rarea_size - (sizeof (GMemArea) - MEM_AREA_SIZE) < mem_chunk->atom_size)
+ rarea_size *= 2;
mem_chunk->area_size = rarea_size - (sizeof (GMemArea) - MEM_AREA_SIZE);
-
+
/*
mem_chunk->area_size -= (sizeof (GMemArea) - MEM_AREA_SIZE);
if (mem_chunk->area_size < mem_chunk->atom_size)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]