[PATCH:libXcursor 1/2] XcursorFileSaveImages: plug memory leak on invalid input

Jeremy Huddleston jeremyhu at apple.com
Tue Nov 29 23:31:01 PST 2011


Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>

On Nov 28, 2011, at 9:10 PM, Alan Coopersmith wrote:

> Error: Memory leak (CWE 401)
>   Memory leak of pointer 'comments' allocated with XcursorCommentsCreate(0)
>        at line 982 of src/file.c in function 'XcursorFileSaveImages'.
>          'comments' allocated at line 978 with XcursorCommentsCreate(0).
>          comments leaks when comments != 0 at line 981.
> 
> [ This bug was found by the Parfait 0.3.7 bug checking tool.
>  For more information see http://labs.oracle.com/projects/parfait/ ]
> 
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
> ---
> src/file.c |    7 +++++--
> 1 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/src/file.c b/src/file.c
> index 631d8f8..efe6d4b 100644
> --- a/src/file.c
> +++ b/src/file.c
> @@ -975,10 +975,13 @@ XcursorFileLoad (FILE		    *file,
> XcursorBool
> XcursorFileSaveImages (FILE *file, const XcursorImages *images)
> {
> -    XcursorComments *comments = XcursorCommentsCreate (0);
> +    XcursorComments *comments;
>     XcursorFile	    f;
>     XcursorBool	    ret;
> -    if (!comments || !file || !images)
> +
> +    if (!file || !images)
> +	return 0;
> +    if ((comments = XcursorCommentsCreate (0)) == NULL)
> 	return 0;
>     _XcursorStdioFileInitialize (file, &f);
>     ret = XcursorXcFileSave (&f, comments, images) && fflush (file) != EOF;
> -- 
> 1.7.3.2
> 
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
> 



More information about the xorg-devel mailing list