dix: protect ChangeWindowDeviceCursor() from allocation failure

On memory allocation failure, return BadAlloc instead of crashing.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2025-05-06 16:04:41 +02:00
parent 8b079ed198
commit 7b7579e956

View File

@ -3486,17 +3486,17 @@ ChangeWindowDeviceCursor(WindowPtr pWin, DeviceIntPtr pDev, CursorPtr pCursor)
} }
else { else {
/* no device cursor yet */ /* no device cursor yet */
DevCursNodePtr pNewNode;
if (!pCursor) if (!pCursor)
return Success; return Success;
pNewNode = malloc(sizeof(DevCursNodeRec)); DevCursNodePtr pNewNode = calloc(1, sizeof(DevCursNodeRec));
if (!pNewNode)
return BadAlloc;
pNewNode->dev = pDev; pNewNode->dev = pDev;
pNewNode->next = pWin->optional->deviceCursors; pNewNode->next = pWin->optional->deviceCursors;
pWin->optional->deviceCursors = pNewNode; pWin->optional->deviceCursors = pNewNode;
pNode = pNewNode; pNode = pNewNode;
} }
if (pCursor && WindowParentHasDeviceCursor(pWin, pDev, pCursor)) if (pCursor && WindowParentHasDeviceCursor(pWin, pDev, pCursor))