diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2012-05-21 09:08:18 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2012-05-31 14:56:45 +1000 |
commit | 8dbee04d4b854d3d8aaf2bf1ba2ea937e8c312b8 (patch) | |
tree | 7329dcb5fe6a85265f5b1b8aa5cbe3d7bee9950f | |
parent | 067ecb5bbd6be2bbc8eb04eacd6b31eab701d58e (diff) |
Add helper functions for X11 private allocation/freeing
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | src/synaptics-x11.c | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/src/synaptics-x11.c b/src/synaptics-x11.c index 37392d4..f379750 100644 --- a/src/synaptics-x11.c +++ b/src/synaptics-x11.c @@ -668,6 +668,27 @@ ReadInput(InputInfoPtr pInfo) SynapticsReadInput(pInfo->private); } +static void FreeX11Private(struct SynapticsX11 **x11) +{ + if ((*x11)->timer) + free((*x11)->timer); + free(*x11); + *x11 = NULL; +} + +struct SynapticsX11 *InitX11Private(void) +{ + struct SynapticsX11 *x11; + + x11 = calloc(1, sizeof(*x11)); + if (x11) { + x11->timer = TimerSet(NULL, 0, 0, NULL, NULL); + if (!x11->timer) + FreeX11Private(&x11); + } + return x11; +} + static int SynapticsPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags) { @@ -677,14 +698,14 @@ SynapticsPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags) char *proto; char *device, *actual_device; - x11 = calloc(1, sizeof(*x11)); + x11 = InitX11Private(); if (!x11) return BadAlloc; /* allocate memory for SynapticsPrivateRec */ priv = SynapticsInitPrivate(); if (!priv) { - free(x11); + FreeX11Private(&x11); return BadAlloc; } @@ -699,14 +720,6 @@ SynapticsPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags) pInfo->switch_mode = SwitchMode; pInfo->private = priv; - /* allocate now so we don't allocate in the signal handler */ - x11->timer = TimerSet(NULL, 0, 0, NULL, NULL); - if (!x11->timer) { - free(x11); - free(priv); - return BadAlloc; - } - proto = xf86SetStrOption(pInfo->options, "Protocol", NULL); device = xf86SetStrOption(pInfo->options, "Device", NULL); /* may change pInfo->options */ @@ -771,9 +784,8 @@ SynapticsPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags) priv->fd = -1; } + FreeX11Private(&x11); free(priv->proto_data); - free(x11->timer); - free(x11); free(priv); pInfo->private = NULL; return BadAlloc; @@ -885,9 +897,8 @@ SynapticsUnInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags) SynapticsPrivate *priv = pInfo->private; if (priv) { struct SynapticsX11 *x11 = priv->frontend_data; - if (x11 && x11->timer) - free(x11->timer); - free(x11); + if (x11) + FreeX11Private(&x11); SynapticsFreePrivate(&priv); } xf86DeleteInput(pInfo, 0); |