summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/synaptics-x11.c41
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);