From 9567fa9a7269765bc59ac71b931e16df261d794d Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 10 Feb 2013 10:24:59 -0800 Subject: [PATCH 1/6] __glXDRIscreenCreateContext: free context on failure, instead of leaking it Reported with other leaks found by cppcheck in bugzilla #50281 https://bugs.freedesktop.org/show_bug.cgi?id=50281 Signed-off-by: Alan Coopersmith Reviewed-by: Ian Romanick --- glx/glxdri.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/glx/glxdri.c b/glx/glxdri.c index a997e2f8a..1964d2e0c 100644 --- a/glx/glxdri.c +++ b/glx/glxdri.c @@ -645,8 +645,10 @@ __glXDRIscreenCreateContext(__GLXscreen * baseScreen, for (i = 0; i < pScreen->numVisuals; i++, visual++) if (visual->vid == glxConfig->visualID) break; - if (i == pScreen->numVisuals) + if (i == pScreen->numVisuals) { + free(context); return NULL; + } context->hwContextID = FakeClientID(0); @@ -655,8 +657,10 @@ __glXDRIscreenCreateContext(__GLXscreen * baseScreen, context->hwContextID, &hwContext); __glXleaveServer(GL_FALSE); - if (!retval) + if (!retval) { + free(context); return NULL; + } context->driContext = screen->legacy->createNewContext(screen->driScreen, config->driConfig, 0, /* render type */ driShare, From 8c5ff2e93f73b24adff741b25fc1e31b2f5dd0ac Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 10 Feb 2013 10:24:59 -0800 Subject: [PATCH 2/6] __glXDRIscreenProbe: free screen when DRI2Connect fails, instead of leaking it Reported with other leaks found by cppcheck in bugzilla #50281 https://bugs.freedesktop.org/show_bug.cgi?id=50281 V2: goto existing error handler, instead of replicating more of it here Signed-off-by: Alan Coopersmith Reviewed-by: Keith Packard --- glx/glxdri2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glx/glxdri2.c b/glx/glxdri2.c index e07cb5632..65485793b 100644 --- a/glx/glxdri2.c +++ b/glx/glxdri2.c @@ -946,7 +946,7 @@ __glXDRIscreenProbe(ScreenPtr pScreen) &screen->fd, &driverName, &deviceName)) { LogMessage(X_INFO, "AIGLX: Screen %d is not DRI2 capable\n", pScreen->myNum); - return NULL; + goto handle_error; } screen->base.destroy = __glXDRIscreenDestroy; From 6bca0184d167388cd417d113031317990489987d Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 10 Feb 2013 10:18:02 -0800 Subject: [PATCH 3/6] dmxVDLRead: if we opened a file, close it instead of leaking it Reported with other leaks found by cppcheck in bugzilla #50281 https://bugs.freedesktop.org/show_bug.cgi?id=50281 Signed-off-by: Alan Coopersmith Reviewed-by: Keith Packard --- hw/dmx/config/dmxcompat.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/dmx/config/dmxcompat.c b/hw/dmx/config/dmxcompat.c index bd9f12738..107991a96 100644 --- a/hw/dmx/config/dmxcompat.c +++ b/hw/dmx/config/dmxcompat.c @@ -228,5 +228,9 @@ dmxVDLRead(const char *filename) break; } } + + if (str != stdin) + fclose(str); + return entry; } From 174ccd84931ece5a92a09c4a1d6a47e0958ebf7e Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 10 Feb 2013 10:24:59 -0800 Subject: [PATCH 4/6] xf86SbusCmapLoadPalette: Delay malloc until needed, avoiding leak on error Reported with other leaks found by cppcheck in bugzilla #50281 https://bugs.freedesktop.org/show_bug.cgi?id=50281 V2: check for malloc failure Signed-off-by: Alan Coopersmith --- hw/xfree86/common/xf86sbusBus.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/xfree86/common/xf86sbusBus.c b/hw/xfree86/common/xf86sbusBus.c index b6a6b94b3..07eb71ed8 100644 --- a/hw/xfree86/common/xf86sbusBus.c +++ b/hw/xfree86/common/xf86sbusBus.c @@ -641,14 +641,16 @@ xf86SbusCmapLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, int i, index; sbusCmapPtr cmap; struct fbcmap fbcmap; - unsigned char *data = malloc(numColors * 3); + unsigned char *data; cmap = SBUSCMAPPTR(pScrn->pScreen); if (!cmap) return; fbcmap.count = 0; fbcmap.index = indices[0]; - fbcmap.red = data; + fbcmap.red = data = malloc(numColors * 3); + if (!data) + return; fbcmap.green = data + numColors; fbcmap.blue = fbcmap.green + numColors; for (i = 0; i < numColors; i++) { From 2b361fbda536f0125e4b87a6d455acc58f4e8690 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 10 Feb 2013 10:24:59 -0800 Subject: [PATCH 5/6] sparcPromPathname2Node: free name when returning error, instead of leaking it Reported with other leaks found by cppcheck in bugzilla #50281 https://bugs.freedesktop.org/show_bug.cgi?id=50281 Signed-off-by: Alan Coopersmith Reviewed-by: Keith Packard --- hw/xfree86/os-support/bus/Sbus.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hw/xfree86/os-support/bus/Sbus.c b/hw/xfree86/os-support/bus/Sbus.c index 826000712..14e6d4bfd 100644 --- a/hw/xfree86/os-support/bus/Sbus.c +++ b/hw/xfree86/os-support/bus/Sbus.c @@ -617,8 +617,10 @@ sparcPromPathname2Node(const char *pathName) return 0; strcpy(name, pathName); name[i + 1] = 0; - if (name[0] != '/') + if (name[0] != '/') { + free(name); return 0; + } p = strchr(name + 1, '/'); if (p) *p = 0; @@ -629,8 +631,10 @@ sparcPromPathname2Node(const char *pathName) *regstr++ = 0; else regstr = p; - if (name + 1 == regstr) + if (name + 1 == regstr) { + free(name); return 0; + } promGetSibling(0); i = promWalkPathname2Node(name + 1, regstr, promRootNode, 0); free(name); From 9878e097a7de2f86eff0dcfd9fe5d83b162197ec Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Wed, 24 Apr 2013 15:24:31 -0700 Subject: [PATCH 6/6] Only call xf86platformVTProbe() when it's defined Fixes build on non-udev systems, since XSERVER_PLATFORM_BUS is only defined in configure.ac if $CONFIG_UDEV_KMS is true. Signed-off-by: Alan Coopersmith Reviewed-by: Dave Airlie --- hw/xfree86/common/xf86Events.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c index ea1842069..7a949fd74 100644 --- a/hw/xfree86/common/xf86Events.c +++ b/hw/xfree86/common/xf86Events.c @@ -561,8 +561,10 @@ xf86VTSwitch(void) for (ih = InputHandlers; ih; ih = ih->next) xf86EnableInputHandler(ih); +#ifdef XSERVER_PLATFORM_BUS /* check for any new output devices */ xf86platformVTProbe(); +#endif OsReleaseSIGIO(); }