[flashrom] [PATCH] fix unchecked malloc calls

Stefan Tauner stefan.tauner at student.tuwien.ac.at
Wed Jul 13 00:40:48 CEST 2011


On Tue, 12 Jul 2011 18:40:20 +0200
Uwe Hermann <uwe at hermann-uwe.de> wrote:

> On Fri, Jul 01, 2011 at 06:05:07AM +0200, Stefan Tauner wrote:
> > compile tested only.
> > btw... why dont we wrap malloc to automatically include these checks?
> > there is probably a patch somewhere that adds totally awesome shutdown code in OOM cases,
> > but afaics we just print a warning and exit right now... it is just stupid to do the checks in the real
> > code then.
> > 
> > Signed-off-by: Stefan Tauner <stefan.tauner at student.tuwien.ac.at>
> 
> It's definately better than what we have now (no error checking at all), so:
> 
> Acked-by: Uwe Hermann <uwe at hermann-uwe.de>

thanks, r1370

> A few notes for later though:
> 
>  - We should call any shutdown function which may need to be called in
>    the respective places (and any free()s which may be needed).

that would probably be handled by int programmer_shutdown(void) in
flashrom.c at the moment. it should either be named differently or
wrapped with a more generic function though(?)

>  - Later we should not exit(1) upon the error, but rather return an
>    error code instead (e.g. FL_ERR_MALLOC or similar), at least in all
>    public "API" functions which are meant to be in the upcoming
>    libflashrom.

and in the internal ones? just as errors values?

>  - A small xmalloc() wrapper (or use another name) would indeed be nice, too,
>    but once we really return error codes etc. it's not really useful
>    anymore I think.

that's true, at least as long as it is not a macro that automagically
returns on errors (which would be super evil, but... well no "but" i
guess. :)

-- 
Kind regards/Mit freundlichen Grüßen, Stefan Tauner




More information about the flashrom mailing list