mi/misprite: use memory management provided by dixRegisterPrivateKey
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: Daniel Stone <daniel@fooishbar.org> Reviewed-by: Rami Ylimäki <rami.ylimaki@vincit.fi> Signed-off-by: Erkki Seppälä <erkki.seppala@vincit.fi>
This commit is contained in:
parent
57b35adaed
commit
f985a7319e
|
@ -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;
|
||||
int ret = miDCDeviceInitialize(pDev, pScreen);
|
||||
|
||||
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;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue
Block a user