xserver: Cleaning up memory allocation functions and macros

Egbert Eich eich at suse.de
Tue May 1 09:33:09 PDT 2007


Magnus Vigerlöf writes:
 > 
 > Imo that's a lazy programmers argument. I can't think of any case where 
 > crashing the Xserver with only an 'Out of memory' in the log will be a 
 > meaningful error message for our end-users.

Lazy programmer, yes.
These should *never* be called in a running Xserver. I would consider
them only useful at *startup( time when no clients are yet connected
and for the unliekly case when there is no memory.
If for example the driver wants to allocate memory for some internal
structures but doesn't get it.
In this case the programmer would just do:
   if (!(foo = (whatever *)xalloc(sizeof(whatever)))) {
      xf86DrvMsg(...,"Out of memory\n");
      return NULL;
   }
and will continue for a while and may crash some point later when some 
code decides that there is no use to continue when no more memory is 
available at that time.
   if we do:
      foo = (whatever *)xnfalloc(sizeof(whatever));
In this case we fail immediately. 
      
 > 
 > If this have been an argument about an X-client I would probably not be as 
 > bothered by this, as that would only affect that program. Annoying, yes but 
 > that wouldn't kill all my other applications that I have running, which would 
 > be the case we're talking about here. 

I think I mentioned that the use of xnfalloc() outside of initialization 
would be a *bad* abuse. 
- When you get an out of memory at initiaization there is probably no use
  continuing.
- When you get an out of memory *after* initialization you need to be
  much more careful with what yo do.

Cheers,
	Egbert.



More information about the xorg mailing list