xf86-video-nested: src/xlibclient.c

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Nov 1 21:32:43 UTC 2024


 src/xlibclient.c |   20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

New commits:
commit 03dab66493622835a29b873cd63df489f1a96ed9
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat Oct 26 09:50:58 2024 -0700

    NestedClientCreateScreen: avoid leaks on failure paths
    
    Found by Oracle Parfait 13.3 static analyzer:
       Memory leak [memory-leak]:
          Memory leak of pointer pPriv allocated with malloc(168)
            at line 182 of xlibclient.c in function 'NestedClientCreateScreen'.
              pPriv allocated at line 177 with malloc(168)
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Part-of: <https://gitlab.freedesktop.org/xorg/driver/xf86-video-nested/-/merge_requests/7>

diff --git a/src/xlibclient.c b/src/xlibclient.c
index 7d5a66d..89bd2d7 100644
--- a/src/xlibclient.c
+++ b/src/xlibclient.c
@@ -174,19 +174,18 @@ NestedClientCreateScreen(int scrnIndex,
     Bool supported;
     char windowTitle[32];
 
-    pPriv = malloc(sizeof(struct NestedClientPrivate));
+    pPriv = calloc(1, sizeof(struct NestedClientPrivate));
     pPriv->scrnIndex = scrnIndex;
 
     pPriv->display = XOpenDisplay(displayName);
     if (!pPriv->display)
-        return NULL;
+        goto bail;
 
     supported = XkbQueryExtension(pPriv->display, &pPriv->xkb.op, &pPriv->xkb.event,
                                   &pPriv->xkb.error, &pPriv->xkb.major, &pPriv->xkb.minor);
     if (!supported) {
         xf86DrvMsg(pPriv->scrnIndex, X_ERROR, "The remote server does not support the XKEYBOARD extension.\n");
-        XCloseDisplay(pPriv->display);
-        return NULL;
+        goto bail;
     }
 
     pPriv->screenNumber = DefaultScreen(pPriv->display);
@@ -228,14 +227,14 @@ NestedClientCreateScreen(int scrnIndex,
                               0 /* XXX: bytes_per_line */);
 
         if (!pPriv->img)
-            return NULL;
+            goto bail;
 
         pPriv->img->data = malloc(pPriv->img->bytes_per_line * pPriv->img->height);
         pPriv->usingShm = FALSE;
     }
 
     if (!pPriv->img->data)
-        return NULL;
+        goto bail;
 
     NestedClientHideCursor(pPriv); /* Hide cursor */
 
@@ -266,6 +265,15 @@ xf86DrvMsg(scrnIndex, X_INFO, "blu_mask: 0x%lx\n", pPriv->img->blue_mask);
     pPriv->dev = (DeviceIntPtr)NULL;
  
     return pPriv;
+
+  bail:
+    if (pPriv->img)
+        /* XDestroyImage will free(pPriv->img->data) for us */
+        XDestroyImage(pPriv->img);
+    if (pPriv->display)
+        XCloseDisplay(pPriv->display);
+    free(pPriv);
+    return NULL;
 }
 
 void NestedClientHideCursor(NestedClientPrivatePtr pPriv) {


More information about the xorg-commit mailing list