[PATCH] Alloc/free drawables array for each ProcPanoramiXShmGetImage call.

Jamey Sharp jamey at minilop.net
Wed Oct 28 16:35:28 PDT 2009


Updates my previous patch, b422b532f3dcab54c53f61a66f2ad76059d1874a.
keithp recommended against allocating the drawables array globally, but my
updated patch with that fixed isn't the patch that landed.

Signed-off-by: Jamey Sharp <jamey at minilop.net>
---
On Wed, Oct 28, 2009 at 08:21:43AM -0700, Keith Packard wrote:
> Excerpts from Jamey Sharp's message of Fri Oct 02 14:10:22 -0700 2009:
> > I'll fix these and the lack of a CloseScreen cleanup hook and send
> > another patch. Thanks!
> 
> I haven't seen another version of this patch float by; did I miss it?

Yes. :-)

 Xext/shm.c |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/Xext/shm.c b/Xext/shm.c
index 8106c40..9e462f2 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -141,7 +141,6 @@ int BadShmSegCode;
 RESTYPE ShmSegType;
 static ShmDescPtr Shmsegs;
 static Bool sharedPixmaps;
-static DrawablePtr *drawables;
 static int shmScrPrivateKeyIndex;
 static DevPrivateKey shmScrPrivateKey = &shmScrPrivateKeyIndex;
 static int shmPixmapPrivateIndex;
@@ -259,13 +258,6 @@ ShmExtensionInit(INITARGS)
     }
 #endif
 
-    drawables = xcalloc(screenInfo.numScreens, sizeof(DrawablePtr));
-    if (!drawables)
-    {
-	ErrorF("MIT-SHM extension disabled: no memory for per-screen drawables\n");
-	return;
-    }
-
     sharedPixmaps = xFalse;
     {
       sharedPixmaps = xTrue;
@@ -618,6 +610,7 @@ static int
 ProcPanoramiXShmGetImage(ClientPtr client)
 {
     PanoramiXRes	*draw;
+    DrawablePtr 	*drawables;
     DrawablePtr 	pDraw;
     xShmGetImageReply	xgi;
     ShmDescPtr		shmdesc;
@@ -678,12 +671,19 @@ ProcPanoramiXShmGetImage(ClientPtr client)
 	    return(BadMatch);
     }
 
+    drawables = xcalloc(PanoramiXNumScreens, sizeof(DrawablePtr));
+    if(!drawables)
+	return(BadAlloc);
+
     drawables[0] = pDraw;
     for(i = 1; i < PanoramiXNumScreens; i++) {
 	rc = dixLookupDrawable(drawables+i, draw->info[i].id, client, 0, 
 			       DixReadAccess);
 	if (rc != Success)
+	{
+	    xfree(drawables);
 	    return rc;
+	}
     }
 
     xgi.visual = wVisual(((WindowPtr)pDraw));
@@ -722,6 +722,7 @@ ProcPanoramiXShmGetImage(ClientPtr client)
 	    }
 	}
     }
+    xfree(drawables);
     
     if (client->swapped) {
 	int n;
-- 
1.6.3.3



More information about the xorg-devel mailing list