[PATCH libXpm] After fdopen(), use fclose() instead of close() in error path

Peter Hutterer peter.hutterer at who-t.net
Tue Oct 2 03:46:50 UTC 2018


On Sun, Sep 30, 2018 at 03:14:00PM -0700, Alan Coopersmith wrote:
> Found by Oracle's Parfait 2.2 static analyzer:
> 
> Error: File Leak
>    File Leak [file-ptr-leak]:
>       Leaked File fp
>         at line 94 of lib/libXpm/src/RdFToBuf.c in function 'XpmReadFileToBuffer
> '.
>           fp initialized at line 86 with fdopen
>           fp leaks when len < 0 at line 92.
> 
> Introduced-by: commit 8b3024e6871ce50b34bf2dff924774bd654703bc
> 
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>

Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

Cheers,
   Peter

> ---
>  src/RdFToBuf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/RdFToBuf.c b/src/RdFToBuf.c
> index 69e3347..1b386f8 100644
> --- a/src/RdFToBuf.c
> +++ b/src/RdFToBuf.c
> @@ -86,15 +86,15 @@ XpmReadFileToBuffer(
>      fp = fdopen(fd, "r");
>      if (!fp) {
>  	close(fd);
>  	return XpmOpenFailed;
>      }
>      len = stats.st_size;
>      if (len < 0 || len >= SIZE_MAX) {
> -	close(fd);
> +	fclose(fp);
>  	return XpmOpenFailed;
>      }
>      ptr = (char *) XpmMalloc(len + 1);
>      if (!ptr) {
>  	fclose(fp);
>  	return XpmNoMemory;
>      }
> -- 
> 2.15.2
> 
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: https://lists.x.org/mailman/listinfo/xorg-devel


More information about the xorg-devel mailing list