[PATCH 2/8] Stop leaking overlayWin in PanoramiXCompositeGetOverlayWindow error paths

Alan Coopersmith alan.coopersmith at oracle.com
Mon Jan 28 17:08:36 PST 2013


Found by parfait 1.1 code analyzer:

Error: Memory leak (CWE 401)
   Memory leak of pointer 'overlayWin' allocated with malloc(72)
        at line 806 of composite/compext.c in function 'PanoramiXCompositeGetOverlayWindow'.
          pointer allocated at line 794 with malloc(72).
          <unknown> leaks when rc != 0 at line 804.
        at line 816 of composite/compext.c in function 'PanoramiXCompositeGetOverlayWindow'.
          pointer allocated at line 794 with malloc(72).
          <unknown> leaks when pOc == NULL at line 815.
        at line 825 of composite/compext.c in function 'PanoramiXCompositeGetOverlayWindow'.
          pointer allocated at line 794 with malloc(72).
          <unknown> leaks when cs->pOverlayWin == NULL at line 822
              and compCreateOverlayWindow(pScreen) == 0 at line 823.
        at line 834 of composite/compext.c in function 'PanoramiXCompositeGetOverlayWindow'.
          pointer allocated at line 794 with malloc(72).
          <unknown> leaks when rc != 0 at line 832.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 composite/compext.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/composite/compext.c b/composite/compext.c
index 8641eff..e4821c5 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -803,6 +803,7 @@ PanoramiXCompositeGetOverlayWindow(ClientPtr client)
                                      RT_WINDOW, client, DixGetAttrAccess);
         if (rc != Success) {
             client->errorValue = stuff->window;
+            free(overlayWin);
             return rc;
         }
         pScreen = pWin->drawable.pScreen;
@@ -812,8 +813,10 @@ PanoramiXCompositeGetOverlayWindow(ClientPtr client)
          * interest in the overlay window
          */
         pOc = compCreateOverlayClient(pScreen, client);
-        if (pOc == NULL)
+        if (pOc == NULL) {
+            free(overlayWin);
             return BadAlloc;
+        }
 
         /*
          * Make sure the overlay window exists
@@ -822,6 +825,7 @@ PanoramiXCompositeGetOverlayWindow(ClientPtr client)
         if (cs->pOverlayWin == NULL)
             if (!compCreateOverlayWindow(pScreen)) {
                 FreeResource(pOc->resource, RT_NONE);
+                free(overlayWin);
                 return BadAlloc;
             }
 
@@ -831,6 +835,7 @@ PanoramiXCompositeGetOverlayWindow(ClientPtr client)
                       DixGetAttrAccess);
         if (rc != Success) {
             FreeResource(pOc->resource, RT_NONE);
+            free(overlayWin);
             return rc;
         }
     }
-- 
1.7.9.2



More information about the xorg-devel mailing list