[PATCH v2] [xorg/xserver] mi/misprite: use memory management provided by dixRegisterPrivateKey

Erkki Seppälä erkki.seppala at vincit.fi
Wed Mar 9 07:29:14 PST 2011


The record allocated by miSpriteDeviceCursorInitialize was not being
released.

This patch makes misprite use dixRegisterPrivateKey with the record
size argument, which handles the memory management
issues. miSpriteDeviceCursorInitialize is restructured to initialize
pCursorInfo only if miDCDeviceInitialize succeeds. The record itself
is zeroed on cleanup to ensure that the assumptions in the code still
hold.

Reviewed-by: Rami Ylimäki <rami.ylimaki at vincit.fi>
Signed-off-by: Erkki Seppälä <erkki.seppala at vincit.fi>
---
 mi/misprite.c |   41 +++++++++++++++++++----------------------
 1 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/mi/misprite.c b/mi/misprite.c
index 770951e..c9d0180 100644
--- a/mi/misprite.c
+++ b/mi/misprite.c
@@ -308,7 +308,7 @@ miSpriteInitialize (ScreenPtr               pScreen,
     if (!dixRegisterPrivateKey(&miSpriteScreenKeyRec, PRIVATE_SCREEN, 0))
 	return FALSE;
 
-    if (!dixRegisterPrivateKey(&miSpriteDevPrivatesKeyRec, PRIVATE_DEVICE, 0))
+    if (!dixRegisterPrivateKey(&miSpriteDevPrivatesKeyRec, PRIVATE_DEVICE, sizeof(miCursorInfoRec)))
 	return FALSE;
 
     pScreenPriv = malloc(sizeof (miSpriteScreenRec));
@@ -860,38 +860,35 @@ miSpriteMoveCursor (DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
 static Bool
 miSpriteDeviceCursorInitialize(DeviceIntPtr pDev, ScreenPtr pScreen)
 {
-    miCursorInfoPtr pCursorInfo;
-    int ret = FALSE;
-
-    pCursorInfo = malloc(sizeof(miCursorInfoRec));
-    if (!pCursorInfo)
-        return FALSE;
-
-    pCursorInfo->pCursor = NULL;
-    pCursorInfo->x = 0;
-    pCursorInfo->y = 0;
-    pCursorInfo->isUp = FALSE;
-    pCursorInfo->shouldBeUp = FALSE;
-    pCursorInfo->pCacheWin = NullWindow;
-    pCursorInfo->isInCacheWin = FALSE;
-    pCursorInfo->checkPixels = TRUE;
-    pCursorInfo->pScreen = FALSE;
+    int ret = miDCDeviceInitialize(pDev, pScreen);
 
-    ret = miDCDeviceInitialize(pDev, pScreen);
-    if (!ret)
+    if (ret)
     {
-        free(pCursorInfo);
-        pCursorInfo = NULL;
+        miCursorInfoPtr pCursorInfo;
+        pCursorInfo = dixLookupPrivate(&pDev->devPrivates, miSpriteDevPrivatesKey);
+        pCursorInfo->pCursor = NULL;
+        pCursorInfo->x = 0;
+        pCursorInfo->y = 0;
+        pCursorInfo->isUp = FALSE;
+        pCursorInfo->shouldBeUp = FALSE;
+        pCursorInfo->pCacheWin = NullWindow;
+        pCursorInfo->isInCacheWin = FALSE;
+        pCursorInfo->checkPixels = TRUE;
+        pCursorInfo->pScreen = FALSE;
     }
-    dixSetPrivate(&pDev->devPrivates, miSpriteDevPrivatesKey, pCursorInfo);
+
     return ret;
 }
 
 static void
 miSpriteDeviceCursorCleanup(DeviceIntPtr pDev, ScreenPtr pScreen)
 {
+    miCursorInfoPtr pCursorInfo = dixLookupPrivate(&pDev->devPrivates, miSpriteDevPrivatesKey);
+
     if (DevHasCursor(pDev))
         miDCDeviceCleanup(pDev, pScreen);
+
+    memset(pCursorInfo, 0, sizeof(miCursorInfoRec));
 }
 
 /*
-- 
1.7.0.4



More information about the xorg-devel mailing list