[PATCH] Check MGAAllocAdaptor() for memory allocation failure

Alan Coopersmith alan.coopersmith at oracle.com
Wed Dec 28 19:51:04 PST 2011


If it couldn't allocate memory, don't attempt to write a bunch of values
to the NULL pointer before returning it, but just pass the NULL along
right away.

Resolves parfait warnings of the form:

Error: Null pointer dereference (CWE 476)
   Write to null pointer 'adapt'
        at line 322 of src/mga_video.c in function 'MGASetupImageVideoTexture'.
          Function 'MGAAllocAdaptor' may return constant 'NULL' at line 237, called at line 320.
          Null pointer introduced at line 237 in function 'MGAAllocAdaptor'.

repeated for every line writing to the adapt pointer in each function.

[ This bug was found by the Parfait 0.4.2 bug checking tool.
  For more information see http://labs.oracle.com/projects/parfait/ ]

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 src/mga_video.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/src/mga_video.c b/src/mga_video.c
index 784e7b1..abce31f 100644
--- a/src/mga_video.c
+++ b/src/mga_video.c
@@ -269,6 +269,8 @@ MGASetupImageVideoOverlay(ScreenPtr pScreen)
     XF86VideoAdaptorPtr adapt;
 
     adapt = MGAAllocAdaptor(pScrn, TRUE);
+    if (adapt == NULL)
+	return NULL;
 
     adapt->type = XvWindowMask | XvInputMask | XvImageMask;
     adapt->flags = VIDEO_OVERLAID_IMAGES | VIDEO_CLIP_TO_VIEWPORT;
@@ -316,6 +318,8 @@ MGASetupImageVideoTexture(ScreenPtr pScreen)
     MGAPtr pMga = MGAPTR(pScrn);
 
     adapt = MGAAllocAdaptor(pScrn, FALSE);
+    if (adapt == NULL)
+	return NULL;
 
     adapt->type = XvWindowMask | XvInputMask | XvImageMask;
     adapt->flags = 0;
@@ -1298,6 +1302,8 @@ MGASetupImageVideoILOAD(ScreenPtr pScreen)
     MGAPtr pMga = MGAPTR(pScrn);
 
     adapt = MGAAllocAdaptor(pScrn, FALSE);
+    if (adapt == NULL)
+	return NULL;
 
     adapt->type = XvWindowMask | XvInputMask | XvImageMask;
     adapt->flags = 0;
-- 
1.7.3.2



More information about the xorg-devel mailing list