[Openchrome-devel] xf86-video-openchrome: src/via_3d.c src/via_dri.c src/via_driver.c src/via_exa.c

James Simmons jsimmons at kemper.freedesktop.org
Tue Jan 13 14:35:50 PST 2015


 src/via_3d.c     |    8 ++++++--
 src/via_dri.c    |    8 ++++++++
 src/via_driver.c |    8 +++-----
 src/via_exa.c    |    5 +++--
 4 files changed, 20 insertions(+), 9 deletions(-)

New commits:
commit 33fcaa11daeb7ca156fcdadd969ca7f950ce8401
Author: James Simmons <jsimmons at infradead.org>
Date:   Tue Jan 13 15:18:28 2015 -0700

    Fixes for various memory related problems discovered by cppcheck.
    The errors are memory leaks, NULL dereferences, and double frees.
    
    Signed-off-by: Oppen <mrugiero at gmail.com>
    Reviewed-by:   James Simmons <jsimmons at infradead.org>

diff --git a/src/via_3d.c b/src/via_3d.c
index 64f40ba..e2d04ff 100644
--- a/src/via_3d.c
+++ b/src/via_3d.c
@@ -257,8 +257,12 @@ viaSet3DCompositeOperator(Via3DState * v3d, CARD8 op)
 {
     ViaCompositeOperator *vOp = viaOperatorModes + op;
 
-    v3d->blendDirty = TRUE;
-    if (v3d && vOp->supported) {
+    if (v3d)
+        v3d->blendDirty = TRUE;
+    else
+        return;
+
+    if (vOp->supported) {
         v3d->blendCol0 = vOp->col0 << 4;
         v3d->blendCol1 = vOp->col1 << 2;
         v3d->blendAl0 = vOp->al0 << 4;
diff --git a/src/via_dri.c b/src/via_dri.c
index c8d3180..2f21a2b 100644
--- a/src/via_dri.c
+++ b/src/via_dri.c
@@ -478,6 +478,14 @@ VIAInitVisualConfigs(ScreenPtr pScreen)
         if (i != numConfigs) {
             xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "[dri] Incorrect "
                        "initialization of visuals.  Disabling DRI.\n");
+
+            if (pConfigs)
+                free(pConfigs);
+            if (pVIAConfigs)
+                free(pVIAConfigs);
+            if (pVIAConfigPtrs)
+                free(pVIAConfigPtrs);
+
             return FALSE;
         }
     }
diff --git a/src/via_driver.c b/src/via_driver.c
index 0679cf2..2fd8f21 100644
--- a/src/via_driver.c
+++ b/src/via_driver.c
@@ -1028,7 +1028,9 @@ VIAPreInit(ScrnInfoPtr pScrn, int flags)
         pVia->ChipRev = pciReadByte(pciTag(0, 0, 0), 0xF6);
 #endif
     }
-    free(pEnt);
+
+    if (pEnt)
+        free(pEnt);
     xf86DrvMsg(pScrn->scrnIndex, from, "Chipset revision: %d\n", pVia->ChipRev);
 
     pVia->directRenderingType = DRI_NONE;
@@ -1106,7 +1108,6 @@ VIAPreInit(ScrnInfoPtr pScrn, int flags)
      */
 
     if (!xf86SetDepthBpp(pScrn, 0, 0, 0, Support32bppFb)) {
-        free(pEnt);
         VIAFreeRec(pScrn);
         return FALSE;
     } else {
@@ -1121,7 +1122,6 @@ VIAPreInit(ScrnInfoPtr pScrn, int flags)
                 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
                            "Given depth (%d) is not supported by this driver\n",
                            pScrn->depth);
-                free(pEnt);
                 VIAFreeRec(pScrn);
                 return FALSE;
         }
@@ -1137,7 +1137,6 @@ VIAPreInit(ScrnInfoPtr pScrn, int flags)
         rgb zeros = { 0, 0, 0 };
 
         if (!xf86SetWeight(pScrn, zeros, zeros)) {
-            free(pEnt);
             VIAFreeRec(pScrn);
             return FALSE;
         } else {
@@ -1154,7 +1153,6 @@ VIAPreInit(ScrnInfoPtr pScrn, int flags)
             xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Given default visual"
                        " (%s) is not supported at depth %d.\n",
                        xf86GetVisualName(pScrn->defaultVisual), pScrn->depth);
-            free(pEnt);
             VIAFreeRec(pScrn);
             return FALSE;
         }
diff --git a/src/via_exa.c b/src/via_exa.c
index d78a770..3ee4921 100644
--- a/src/via_exa.c
+++ b/src/via_exa.c
@@ -217,9 +217,10 @@ viaSetupCBuffer(ScrnInfoPtr pScrn, ViaCommandBuffer *cb, unsigned size)
 static void
 viaTearDownCBuffer(ViaCommandBuffer *cb)
 {
-    if (cb && cb->buf)
+    if (cb && cb->buf) {
         free(cb->buf);
-    cb->buf = NULL;
+        cb->buf = NULL;
+    }
 }
 
 /*


More information about the Openchrome-devel mailing list