diff options
Diffstat (limited to 'xorg-server/Xi/exevents.c')
-rw-r--r-- | xorg-server/Xi/exevents.c | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/xorg-server/Xi/exevents.c b/xorg-server/Xi/exevents.c index 8172f611d..35f929731 100644 --- a/xorg-server/Xi/exevents.c +++ b/xorg-server/Xi/exevents.c @@ -1632,6 +1632,19 @@ SelectForWindow(DeviceIntPtr dev, WindowPtr pWin, ClientPtr client, return Success; } +static void +FreeInputClient(InputClientsPtr *other) +{ + free(*other); + *other = NULL; +} + +static InputClientsPtr +AllocInputClient(void) +{ + return calloc(1, sizeof(InputClients)); +} + int AddExtensionClient(WindowPtr pWin, ClientPtr client, Mask mask, int mskidx) { @@ -1639,7 +1652,7 @@ AddExtensionClient(WindowPtr pWin, ClientPtr client, Mask mask, int mskidx) if (!pWin->optional && !MakeWindowOptional(pWin)) return BadAlloc; - others = calloc(1, sizeof(InputClients)); + others = AllocInputClient(); if (!others) return BadAlloc; if (!pWin->optional->inputMasks && !MakeInputMasks(pWin)) @@ -1653,7 +1666,7 @@ AddExtensionClient(WindowPtr pWin, ClientPtr client, Mask mask, int mskidx) return Success; bail: - free(others); + FreeInputClient(&others); return BadAlloc; } @@ -1669,6 +1682,13 @@ MakeInputMasks(WindowPtr pWin) return TRUE; } +static void +FreeInputMask(OtherInputMasks **imask) +{ + free(*imask); + *imask = NULL; +} + void RecalculateDeviceDeliverableEvents(WindowPtr pWin) { @@ -1729,14 +1749,15 @@ InputClientGone(WindowPtr pWin, XID id) if (other->resource == id) { if (prev) { prev->next = other->next; - free(other); + FreeInputClient(&other); } else if (!(other->next)) { if (ShouldFreeInputMasks(pWin, TRUE)) { - wOtherInputMasks(pWin)->inputClients = other->next; - free(wOtherInputMasks(pWin)); + OtherInputMasks *mask = wOtherInputMasks(pWin); + mask->inputClients = other->next; + FreeInputMask(&mask); pWin->optional->inputMasks = (OtherInputMasks *) NULL; CheckWindowOptionalNeed(pWin); - free(other); + FreeInputClient(&other); } else { other->resource = FakeClientID(0); if (!AddResource(other->resource, RT_INPUTCLIENT, @@ -1745,7 +1766,7 @@ InputClientGone(WindowPtr pWin, XID id) } } else { wOtherInputMasks(pWin)->inputClients = other->next; - free(other); + FreeInputClient(&other); } RecalculateDeviceDeliverableEvents(pWin); return Success; |