[PATCHv2 04/13] xfree86: dri2: fix memory leak and free resources properly

Tiago Vignatti tiago.vignatti at nokia.com
Mon Mar 28 06:14:26 PDT 2011


Signed-off-by: Tiago Vignatti <tiago.vignatti at nokia.com>
Reviewed-by: Nicolas Peninguy <nico at lostgeeks.org>
---
 hw/xfree86/dri2/dri2.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
index 9ca378f..10be599 100644
--- a/hw/xfree86/dri2/dri2.c
+++ b/hw/xfree86/dri2/dri2.c
@@ -221,11 +221,16 @@ DRI2AddDrawableRef(DRI2DrawablePtr pPriv, XID id, XID dri2_id,
     if (ref == NULL)
 	return BadAlloc;
 	
-    if (!AddResource(dri2_id, dri2DrawableRes, pPriv))
+    if (!AddResource(dri2_id, dri2DrawableRes, pPriv)) {
+	free(ref);
 	return BadAlloc;
+    }
     if (!DRI2LookupDrawableRef(pPriv, id))
-	if (!AddResource(id, dri2DrawableRes, pPriv))
+	if (!AddResource(id, dri2DrawableRes, pPriv)) {
+	    FreeResourceByType(dri2_id, dri2DrawableRes, TRUE);
+	    free(ref);
 	    return BadAlloc;
+        }
 
     ref->id = id;
     ref->dri2_id = dri2_id; 
-- 
1.7.0.4



More information about the xorg-devel mailing list