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

Alan Coopersmith alan.coopersmith at oracle.com
Fri Jun 4 08:48:07 PDT 2010


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 <alan.coopersmith at oracle.com>
---
 hw/xfree86/os-support/solaris/sun_agp.c |   10 +++++-----
 1 files 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 ccecd11..95ab1b5 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;
 	}
 
-- 
1.5.6.5



More information about the xorg-devel mailing list