[PATCH:mkfontscale 2/2] makeList: free partially allocated list on failure

Julien Cristau jcristau at debian.org
Fri Feb 25 10:28:26 PST 2011


On Thu, Feb 24, 2011 at 23:38:45 -0800, Alan Coopersmith wrote:

> Error: Memory leak (CWE 401)
>    Memory leak of pointer 'first' allocated with malloc(8)
>         at line 192 of list.c in function 'makeList'.
>           'first' allocated at line 181 with malloc(8).
>           first leaks when next == 0 at line 191.
> 
> [ This bug was found by the Parfait 0.3.6 bug checking tool.
>   For more information see http://labs.oracle.com/projects/parfait/ ]
> 
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
> ---
>  list.c |    4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)
> 
> diff --git a/list.c b/list.c
> index fdf81d3..a10b5ed 100644
> --- a/list.c
> +++ b/list.c
> @@ -188,8 +188,10 @@ makeList(char **a, int n, ListPtr old, int begin)
>      current = first;
>      for(i = 1; i < n; i++) {
>          next = malloc(sizeof(ListRec));
> -        if(!next)
> +        if(!next) {
> +            destroyList(first);
>              return NULL;
> +        }
>          next->value = a[i];
>          next->next = NULL;
>  
Reviewed-by: Julien Cristau <jcristau at debian.org>

Cheers,
Julien


More information about the xorg-devel mailing list