From 8ff9b502cfce3828f7855ffba7949d6ebee34031 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 4 Jun 2010 08:44:02 -0700 Subject: Solaris: avoid memory leak if AGPIOC_INFO ioctl fails Move malloc after ioctl, so we don't have to worry about free'ing the memory if the ioctl fails. [ This bug was found by the Parfait bug checking tool. For more information see http://research.sun.com/projects/parfait ] Signed-off-by: Alan Coopersmith Reviewed-by: Mikhail Gusarov --- hw/xfree86/os-support/solaris/sun_agp.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/xfree86/os-support/solaris/sun_agp.c b/hw/xfree86/os-support/solaris/sun_agp.c index 734a6e1a6..9db5d6368 100644 --- a/hw/xfree86/os-support/solaris/sun_agp.c +++ b/hw/xfree86/os-support/solaris/sun_agp.c @@ -115,16 +115,16 @@ xf86GetAGPInfo(int screenNum) if (!GARTInit(screenNum)) return NULL; - if ((info = calloc(sizeof(AgpInfo), 1)) == NULL) { + if (ioctl(gartFd, AGPIOC_INFO, &agpinf) != 0) { xf86DrvMsg(screenNum, X_ERROR, - "xf86GetAGPInfo: Failed to allocate AgpInfo\n"); + "xf86GetAGPInfo: AGPIOC_INFO failed (%s)\n", + strerror(errno)); return NULL; } - if (ioctl(gartFd, AGPIOC_INFO, &agpinf) != 0) { + if ((info = calloc(sizeof(AgpInfo), 1)) == NULL) { xf86DrvMsg(screenNum, X_ERROR, - "xf86GetAGPInfo: AGPIOC_INFO failed (%s)\n", - strerror(errno)); + "xf86GetAGPInfo: Failed to allocate AgpInfo\n"); return NULL; } -- cgit v1.2.3