From df0b2ce823e8bc9e994875ce349cf1da4cf8e402 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Tue, 12 Jul 2016 11:02:15 +0200 Subject: intel: Fix fd (and mem) leak when intel_scrn_create fails The probe functions in intel_module.c call intel_open_device() before calling intel_scrn_create(), but if the later fails because of e.g. an allocation failure they were not cleaning up the resources claimed by intel_open_device(), esp. leaking the fd is a problem because this breaks the fallback to the modesetting driver. This commit fixes this by adding a intel_close_device() cleanup function and calling that when intel_scrn_create() fails. Signed-off-by: Hans de Goede --- src/intel_device.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/intel_device.c') diff --git a/src/intel_device.c b/src/intel_device.c index 54c14436..04ad7b6a 100644 --- a/src/intel_device.c +++ b/src/intel_device.c @@ -643,6 +643,27 @@ err_path: return -1; } +void intel_close_device(int entity_num) +{ + struct intel_device *dev; + + if (intel_device_key == -1) + return; + + dev = xf86GetEntityPrivate(entity_num, intel_device_key)->ptr; + xf86GetEntityPrivate(entity_num, intel_device_key)->ptr = NULL; + if (!dev) + return; + + if (dev->master_count == 0) /* Don't close server-fds */ + close(dev->fd); + + if (dev->render_node != dev->master_node) + free(dev->render_node); + free(dev->master_node); + free(dev); +} + int __intel_peek_fd(ScrnInfoPtr scrn) { struct intel_device *dev; -- cgit v1.2.3