From d13cea6ccb73bac7e4ae0dd1f4b0fb6ab24a86ab Mon Sep 17 00:00:00 2001 From: Michal Lazo Date: Mon, 16 Sep 2019 16:34:39 +0000 Subject: [PATCH] kms-device: Handle impl device creation failure Properly free kms-device in case of invalid initialization https://gitlab.gnome.org/GNOME/mutter/merge_requests/772 --- src/backends/native/meta-kms-device.c | 33 +++++++++++++++------------ 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/backends/native/meta-kms-device.c b/src/backends/native/meta-kms-device.c index be0362ddc..bda3859d1 100644 --- a/src/backends/native/meta-kms-device.c +++ b/src/backends/native/meta-kms-device.c @@ -211,6 +211,7 @@ meta_kms_device_new (MetaKms *kms, return NULL; device = g_object_new (META_TYPE_KMS_DEVICE, NULL); + device->kms = kms; data = (CreateImplDeviceData) { .device = device, @@ -224,7 +225,6 @@ meta_kms_device_new (MetaKms *kms, return NULL; } - device->kms = kms; device->impl_device = data.out_impl_device; device->flags = flags; device->path = g_strdup (path); @@ -266,27 +266,30 @@ meta_kms_device_finalize (GObject *object) MetaBackend *backend = meta_kms_get_backend (device->kms); MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend); MetaLauncher *launcher = meta_backend_native_get_launcher (backend_native); - FreeImplDeviceData data; - GError *error = NULL; g_list_free (device->crtcs); g_list_free (device->connectors); g_list_free (device->planes); - data = (FreeImplDeviceData) { - .impl_device = device->impl_device, - }; - if (!meta_kms_run_impl_task_sync (device->kms, free_impl_device_in_impl, &data, - &error)) + if (device->impl_device) { - g_warning ("Failed to close KMS impl device: %s", error->message); - g_error_free (error); - } - else - { - meta_launcher_close_restricted (launcher, data.out_fd); - } + FreeImplDeviceData data; + GError *error = NULL; + data = (FreeImplDeviceData) { + .impl_device = device->impl_device, + }; + if (!meta_kms_run_impl_task_sync (device->kms, free_impl_device_in_impl, &data, + &error)) + { + g_warning ("Failed to close KMS impl device: %s", error->message); + g_error_free (error); + } + else + { + meta_launcher_close_restricted (launcher, data.out_fd); + } + } G_OBJECT_CLASS (meta_kms_device_parent_class)->finalize (object); }