[PATCH] Solaris: avoid memory leak if AGPIOC_INFO ioctl fails

Mikhail Gusarov dottedmag at dottedmag.net
Fri Jun 4 08:51:45 PDT 2010


Twas brillig at 08:48:07 04.06.2010 UTC-07 when alan.coopersmith at oracle.com did gyre and gimble:

 AC> Move malloc after ioctl, so we don't have to worry about free'ing the
 AC> memory if the ioctl fails.

 AC> [ This bug was found by the Parfait bug checking tool.
 AC>   For more information see http://research.sun.com/projects/parfait ]

 AC> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>

Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>

 AC> -        if ((info = calloc(sizeof(AgpInfo), 1)) == NULL) {
 AC> +        if (ioctl(gartFd, AGPIOC_INFO, &agpinf) != 0) {
 AC>                  xf86DrvMsg(screenNum, X_ERROR,
 AC> -                    "xf86GetAGPInfo: Failed to allocate AgpInfo\n");
 AC> +                    "xf86GetAGPInfo: AGPIOC_INFO failed (%s)\n",
 AC> +                    strerror(errno));
 AC>                  return NULL;
 AC>          }
 AC>  
 AC> -        if (ioctl(gartFd, AGPIOC_INFO, &agpinf) != 0) {
 AC> +        if ((info = calloc(sizeof(AgpInfo), 1)) == NULL) {
 AC>                  xf86DrvMsg(screenNum, X_ERROR,
 AC> -                    "xf86GetAGPInfo: AGPIOC_INFO failed (%s)\n",
 AC> -                    strerror(errno));
 AC> +                    "xf86GetAGPInfo: Failed to allocate AgpInfo\n");
 AC>                  return NULL;
 AC>          }

diff(1) did the really amazing job here :)

-- 
  http://fossarchy.blogspot.com/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg-devel/attachments/20100604/9dfc3d69/attachment.pgp>


More information about the xorg-devel mailing list