Re: patch



On Tue, 27 Apr 1999, Martin Pool wrote:

> The current implementation in gmem.c never frees memory when
> ENABLE_MEM_CHECK is set.  I thought this was a bug, but now I see it may
> be intentional.  Can somebody please tell me which it is?

imho, that's been intentional. it actually is a matter of what exactly we
want ENABLE_MEM_CHECK to do.

> >  ***************
> > > *** 405,415 ****
> > >         g_warning ("freeing previously freed memory\n");
> > >         *t += 1;
> > >         mem = t;
> > >
> > > -       memset ((guchar*) mem + 8, 0, size);
> > > +       memset ((guchar*) mem + 2 * SIZEOF_LONG, GARBAGE_FILL, size);
> > > +       realloc ((guchar*) mem, 2 * SIZEOF_LONG);
> > 
> > i.e. free only the cluttered area
> 
> Isn't it possible that some allocators will move blocks when they
> shrink? 
> <http://www.gnu.org/manual/glibc-2.0.6/html_node/libc_25.html#SEC25>
> seems to suggest so.
> 
> There's no way to safely shrink the block down to just the debugging
> fields.

yes, you are right, point taken.

> > >
> > > --- 409,419 ----
> > > -       g_warning ("freeing previously freed memory\n");
> > > +       g_warning ("will not free previously freed (%d) memory\n", *t);
> > >         *t += 1;
> > >         mem = t;
> > >
> > > -       free (mem);
> > 
> > to avoid double-frees that will give trouble anyways.
> 
> Sure, that sounds good.
> 
> > but since this is changing semantics of ENABLE_MEM_CHECK in major
> > ways, we should discuss this on gtk-devel-list@redhat.com first
> > (feel free to Cc: to that list on replies).
> 
> Arguably the right place to do this stuff is in the malloc library, and
> we should just suggest that people use a debugging-malloc or
> ElectricFence to test their code.

yeah, i much agree with you here. i've recently thought about extending
the glib memory debugging behaviour, and took a deeper look at the dmalloc
implementation. i actually ended up deciding that we wouldn't want to feature
all those kinds of nice options that a dmalloc package provides in glib
directly. imho, users are better off, using a full featured malloc debuging
package to test their programs with, rather than reinventing yet-another wheel
in glib.

---
ciaoTJ



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