From 44968da376c880e096225f149f78673aa4c6e5e0 Mon Sep 17 00:00:00 2001 From: Kyle Guinn Date: Fri, 23 Sep 2016 15:03:34 +0300 Subject: [PATCH] xfree86: Fix null pointer dereference Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=93675 Signed-off-by: Kyle Guinn [hdegoede@redhat.com: Simplify by adding 2 if conds together with &&] Signed-off-by: Hans de Goede --- hw/xfree86/i2c/xf86i2c.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/xfree86/i2c/xf86i2c.c b/hw/xfree86/i2c/xf86i2c.c index 2a8b8df22..22109cfbc 100644 --- a/hw/xfree86/i2c/xf86i2c.c +++ b/hw/xfree86/i2c/xf86i2c.c @@ -614,7 +614,7 @@ xf86CreateI2CDevRec(void) void xf86DestroyI2CDevRec(I2CDevPtr d, Bool unalloc) { - if (d) { + if (d && d->pI2CBus) { I2CDevPtr *p; /* Remove this from the list of active I2C devices. */ @@ -628,10 +628,10 @@ xf86DestroyI2CDevRec(I2CDevPtr d, Bool unalloc) xf86DrvMsg(d->pI2CBus->scrnIndex, X_INFO, "I2C device \"%s:%s\" removed.\n", d->pI2CBus->BusName, d->DevName); - - if (unalloc) - free(d); } + + if (unalloc) + free(d); } /* I2C transmissions are related to an I2CDevRec you must link to a