[vlc-devel] [VLC] #2366: realloc is generally used incorrectly

Laurent Aimar fenrir at via.ecp.fr
Mon May 25 20:55:02 CEST 2009


Hi,

On Mon, May 25, 2009, Rémi Denis-Courmont wrote:
> A demand-paging operating system will hit OOM when memory is accessed, _not_ 
> when memory is allocated. The C language provides no (portable) way to handle 
> errors during memory accesses. Checking for realloc() errors will not fix out-
> of-memory handling; it would however fix out-of-address-space handling (i.e. 
> ridiculously large allocation requests), if and only if we were to fix 
> malloc() and calloc() as well, including in all underlying libraries.

 I wonder if we should not take a more pragmatic approche:
 [a] check for malloc/calloc/realloc everytime the memory needed is known to
be potentially large or value comming from untrusted source (files, net, ...).
 [b] do not check for known small amount (like strings, small structures, etc)

 The code path from a malloc failure is in practice never tested, and so will be
full of bugs. There is no way to escape that. Limiting the attention to where it is
really dangerous (or more probable) will probably make a better code and ease dev
and so increase code quality.

 As said courmish, most of our dependencies do not check for malloc failure,
and so making our attemps in VLC mostly useless except I hope/think in case [a].

Regards,

-- 
fenrir




More information about the vlc-devel mailing list