[PATCH 1/5] __glXDRIscreenCreateContext: free context on failure, instead of leaking it

Alan Coopersmith alan.coopersmith at oracle.com
Mon Apr 1 22:09:19 PDT 2013


Reported with other leaks found by cppcheck in bugzilla #50281
https://bugs.freedesktop.org/show_bug.cgi?id=50281

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
---
 glx/glxdri.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/glx/glxdri.c b/glx/glxdri.c
index a997e2f..1964d2e 100644
--- a/glx/glxdri.c
+++ b/glx/glxdri.c
@@ -645,8 +645,10 @@ __glXDRIscreenCreateContext(__GLXscreen * baseScreen,
     for (i = 0; i < pScreen->numVisuals; i++, visual++)
         if (visual->vid == glxConfig->visualID)
             break;
-    if (i == pScreen->numVisuals)
+    if (i == pScreen->numVisuals) {
+        free(context);
         return NULL;
+    }
 
     context->hwContextID = FakeClientID(0);
 
@@ -655,8 +657,10 @@ __glXDRIscreenCreateContext(__GLXscreen * baseScreen,
                               context->hwContextID, &hwContext);
     __glXleaveServer(GL_FALSE);
 
-    if (!retval)
+    if (!retval) {
+        free(context);
         return NULL;
+    }
 
     context->driContext = screen->legacy->createNewContext(screen->driScreen, config->driConfig, 0,     /* render type */
                                                            driShare,
-- 
1.7.9.2



More information about the xorg-devel mailing list