xf86XvMCScreenInit: Avoid leak if dixRegisterPrivateKey fails
authorAlan Coopersmith <alan.coopersmith@oracle.com>
Sun, 27 Jan 2013 22:00:54 +0000 (14:00 -0800)
committerAlan Coopersmith <alan.coopersmith@oracle.com>
Wed, 6 Feb 2013 02:34:57 +0000 (18:34 -0800)
Found by parfait 1.1 memory analyser:
   Memory leak of pointer 'pAdapt' allocated with malloc((88 * num_adaptors))
        at line 162 of hw/xfree86/common/xf86xvmc.c in function 'xf86XvMCScreenInit'.
          'pAdapt' allocated at line 158 with malloc((88 * num_adaptors)).

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
hw/xfree86/common/xf86xvmc.c

index 78a32bf..3169c05 100644 (file)
@@ -158,8 +158,10 @@ xf86XvMCScreenInit(ScreenPtr pScreen,
     if (!(pAdapt = malloc(sizeof(XvMCAdaptorRec) * num_adaptors)))
         return FALSE;
 
-    if (!dixRegisterPrivateKey(&XF86XvMCScreenKeyRec, PRIVATE_SCREEN, 0))
+    if (!dixRegisterPrivateKey(&XF86XvMCScreenKeyRec, PRIVATE_SCREEN, 0)) {
+        free(pAdapt);
         return FALSE;
+    }
 
     if (!(pScreenPriv = malloc(sizeof(xf86XvMCScreenRec)))) {
         free(pAdapt);