From f8f6783b9d4bc4106a33e43a1ddb9c0744e2c741 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 4 Jul 2011 14:14:39 +1000 Subject: xfree86: duplicate xorg.conf device information before xf86NewInputDevice xf86ConfigLayout.inputs contains the information from the xorg.conf file. Passing this into xf86NewInputDevice means the device will get cleaned up on exit and the pointers in xf86ConfigLayout.inputs are left dangling. In the second server generation, this results in a server crash. Also, rename pDev to pInfo. pDev is pretty much reserved for DeviceIntPtr types. Reproducible: AutoAddDevices off and xorg.conf input sections, trigger server regeneration. Signed-off-by: Peter Hutterer Reviewed-by: Daniel Stone (cherry picked from commit f0d7e9db28c374a3db359bcb63a7ce79fd84b541) --- hw/xfree86/common/xf86Init.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c index 0b36163c0..7d9bce9b8 100644 --- a/hw/xfree86/common/xf86Init.c +++ b/hw/xfree86/common/xf86Init.c @@ -791,6 +791,21 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv) NULL); } +static InputInfoPtr +duplicateDevice(InputInfoPtr pInfo) +{ + InputInfoPtr dup = calloc(1, sizeof(InputInfoRec)); + if (dup) { + dup->name = strdup(pInfo->name); + dup->driver = strdup(pInfo->driver); + dup->options = xf86OptionListDuplicate(pInfo->options); + /* type_name is a const string */ + dup->type_name = pInfo->type_name; + dup->fd = -1; + } + return dup; +} + /* * InitInput -- * Initialize all supported input devices. @@ -799,7 +814,7 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv) void InitInput(int argc, char **argv) { - InputInfoPtr* pDev; + InputInfoPtr* pInfo; DeviceIntPtr dev; xf86Info.vtRequestsPending = FALSE; @@ -809,14 +824,21 @@ InitInput(int argc, char **argv) GetEventList(&xf86Events); /* Initialize all configured input devices */ - for (pDev = xf86ConfigLayout.inputs; pDev && *pDev; pDev++) { + for (pInfo = xf86ConfigLayout.inputs; pInfo && *pInfo; pInfo++) { + InputInfoPtr dup; /* Replace obsolete keyboard driver with kbd */ - if (!xf86NameCmp((*pDev)->driver, "keyboard")) { - strcpy((*pDev)->driver, "kbd"); + if (!xf86NameCmp((*pInfo)->driver, "keyboard")) { + strcpy((*pInfo)->driver, "kbd"); } + /* Data passed into xf86NewInputDevice will be freed on shutdown. + * Duplicate from xf86ConfigLayout.inputs, otherwise we don't have any + * xorg.conf input devices in the second generation + */ + dup = duplicateDevice(*pInfo); + /* If one fails, the others will too */ - if (xf86NewInputDevice(*pDev, &dev, TRUE) == BadAlloc) + if (xf86NewInputDevice(dup, &dev, TRUE) == BadAlloc) break; } -- cgit v1.2.3