[flashrom] [PATCH] Fix flashrom memory leaks

Maciej Pijanka maciej.pijanka at gmail.com
Sat Sep 19 13:13:54 CEST 2009


On 18/09/2009, ron minnich <rminnich at gmail.com> wrote:
> OK, if you're going to do this:
>
> if (x) {
>    message
>    exit
> }
>
> all over the place, why not do this instead:
>
> void *xalloc(size_t amount, char *msg)
> {
>    void *ret = alloc(amount);
>    if (! ret) {
>      fprintf(stderr, "%s: Alloc of %d bytes failed\n", msg, amount);
>      exit(1);
>    }
> }
>
> same for realloc.
>
> Why? because:
> 1. you're repeating the same code over and over
> 2. you're not telling people where you failed, or how much you tried to
> allocate
>     this kind of fatal error should be informative
>
> just a comment

if xalloc will be done as macro then its possible to use __LINE__ and
__FILE__ values to show from where xalloc was called

#declare xalloc(a,b) xalloc(a,b,__FILE__, __LINE__)

or similar construction

just my 1e-30 of comments

best regards
Maciej

-- 
Maciej Pijanka, PLD-Linux Developer, Reg Linux user #133161
POE/Perl user




More information about the flashrom mailing list