[PATCH 2/6] xserver: Possible memory leaks, stricter option checks, UnInit (NewInputDeviceRequest)

Magnus Vigerlöf Magnus.Vigerlof at home.se
Fri Mar 30 15:13:10 PDT 2007


On Friday 30 March 2007 23:04, Jesse Barnes wrote:
[...]
> > I don't have any problem to start crawl through the code and start
> > fixing these kinds of things. But shouldn't we address all the different
> > naming schemes and implementation around malloc (et al) at the same
> > time? For malloc I've found the following defines/functions so far in
> > xserver: xalloc, xnfalloc, Xalloc, __glXMalloc, XtMalloc, and
> > xf86confmalloc. Some are needed, but not all for sure... Eliminate all
> > but xalloc, Xalloc, xnf*, and XNF*? Maybe even the ones starting with
> > 'x' as well?
>
> Yes please.  It would be great if we could just use the C library routines
> directly...

Can the xserver really start using the standard C library methods? I'm not so 
sure as the Xalloc do some really nifty things (mmap) for big allocations, 
and I do think they are needed to be kept like that.

> > Is there a macro that set the freed pointer to NULL after freeing the
> > memory somewhere? I'd prefer a clean SEGV instead of an obscure error
> > that is caused by a stray pointer... And if that can be made in a simple
> > manner in the code I'd be happy. XfreeZ(ptr) ?
>
> If we free memory twice (as opposed to freeing NULL pointers) we probably
> want to catch that rather than have the second free be a no-op (as it
> would be if free set the pointer to NULL).  Usually that means turning on
> some sort of malloc/free checking though...

I didn't thought of that specific case.. But I'm not sure how big loss that 
would be.. If there's only one pointer and that is null, then there's no 
problem unless the freed memory is accessed where we'll get a SEGV instead of 
(potentially) something fishy. The most common problem with double free is 
(in my experience) two different structures that holds a pointer to the same 
memory and in this case if the memory is freed from both structures we'll 
still have a double free with or without setting the pointer to NULL.

Cheers
 Magnus V



More information about the xorg mailing list