Fix cursor ref counting mistakes with sprites and xf86Cursor.c

A few cursor value assignments weren't getting correctly ref counted,
causing leaks of cursor objects.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
(cherry picked from commit cdeb2c23f8)
This commit is contained in:
Keith Packard 2010-04-30 12:18:09 -07:00 committed by Peter Hutterer
parent afd730f57f
commit ede10681c4
3 changed files with 19 additions and 5 deletions

View file

@ -857,6 +857,8 @@ CloseDevice(DeviceIntPtr dev)
}
if (DevHasCursor(dev) && dev->spriteInfo->sprite) {
if (dev->spriteInfo->sprite->current)
FreeCursor(dev->spriteInfo->sprite->current, None);
xfree(dev->spriteInfo->sprite->spriteTrace);
xfree(dev->spriteInfo->sprite);
}

View file

@ -2943,6 +2943,7 @@ InitializeSprite(DeviceIntPtr pDev, WindowPtr pWin)
{
SpritePtr pSprite;
ScreenPtr pScreen;
CursorPtr pCursor;
if (!pDev->spriteInfo->sprite)
{
@ -2986,8 +2987,7 @@ InitializeSprite(DeviceIntPtr pDev, WindowPtr pWin)
if (pWin)
{
pSprite->current = wCursor(pWin);
pSprite->current->refcnt++;
pCursor = wCursor(pWin);
pSprite->spriteTrace = (WindowPtr *)xcalloc(1, 32*sizeof(WindowPtr));
if (!pSprite->spriteTrace)
FatalError("Failed to allocate spriteTrace");
@ -3000,13 +3000,18 @@ InitializeSprite(DeviceIntPtr pDev, WindowPtr pWin)
pSprite->pDequeueScreen = pSprite->pEnqueueScreen;
} else {
pSprite->current = NullCursor;
pCursor = NullCursor;
pSprite->spriteTrace = NULL;
pSprite->spriteTraceSize = 0;
pSprite->spriteTraceGood = 0;
pSprite->pEnqueueScreen = screenInfo.screens[0];
pSprite->pDequeueScreen = pSprite->pEnqueueScreen;
}
if (pCursor)
pCursor->refcnt++;
if (pSprite->current)
FreeCursor(pSprite->current, None);
pSprite->current = pCursor;
if (pScreen)
{
@ -3059,6 +3064,7 @@ UpdateSpriteForScreen(DeviceIntPtr pDev, ScreenPtr pScreen)
{
SpritePtr pSprite = NULL;
WindowPtr win = NULL;
CursorPtr pCursor;
if (!pScreen)
return ;
@ -3074,8 +3080,12 @@ UpdateSpriteForScreen(DeviceIntPtr pDev, ScreenPtr pScreen)
pSprite->hotLimits.x2 = pScreen->width;
pSprite->hotLimits.y2 = pScreen->height;
pSprite->win = win;
pSprite->current = wCursor (win);
pSprite->current->refcnt++;
pCursor = wCursor(win);
if (pCursor)
pCursor->refcnt++;
if (pSprite->current)
FreeCursor(pSprite->current, 0);
pSprite->current = pCursor;
pSprite->spriteTraceGood = 1;
pSprite->spriteTrace[0] = win;
(*pScreen->CursorLimits) (pDev,

View file

@ -312,6 +312,8 @@ xf86CursorSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCurs,
xf86SetCursor(pScreen, NullCursor, x, y);
ScreenPriv->isUp = FALSE;
}
if (ScreenPriv->CurrentCursor)
FreeCursor(ScreenPriv->CurrentCursor, None);
ScreenPriv->CurrentCursor = NullCursor;
return;
}