From bfd1c16e87cf9f90e8fe039b4bab400c68fb68a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 24 Jul 2019 16:49:38 +0200 Subject: [PATCH 06/28] clutter/backend: Use an auto-pointer to handle the template on creation We allocate a CoglOnscreenTemplate but this is not unreffed if we have an error, so let's just use an auto-pointer to manage its lifecycle. https://gitlab.gnome.org/GNOME/mutter/merge_requests/682 --- clutter/clutter/clutter-backend.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/clutter/clutter/clutter-backend.c b/clutter/clutter/clutter-backend.c index 30ebe5ef1..69aeec5eb 100644 --- a/clutter/clutter/clutter-backend.c +++ b/clutter/clutter/clutter-backend.c @@ -234,81 +234,79 @@ clutter_backend_do_real_create_context (ClutterBackend *backend, klass = CLUTTER_BACKEND_GET_CLASS (backend); swap_chain = NULL; internal_error = NULL; CLUTTER_NOTE (BACKEND, "Creating Cogl renderer"); backend->cogl_renderer = klass->get_renderer (backend, &internal_error); if (backend->cogl_renderer == NULL) goto error; CLUTTER_NOTE (BACKEND, "Connecting the renderer"); cogl_renderer_set_driver (backend->cogl_renderer, driver_id); if (!cogl_renderer_connect (backend->cogl_renderer, &internal_error)) goto error; CLUTTER_NOTE (BACKEND, "Creating Cogl swap chain"); swap_chain = cogl_swap_chain_new (); CLUTTER_NOTE (BACKEND, "Creating Cogl display"); if (klass->get_display != NULL) { backend->cogl_display = klass->get_display (backend, backend->cogl_renderer, swap_chain, &internal_error); } else { - CoglOnscreenTemplate *tmpl; + g_autoptr (CoglOnscreenTemplate) tmpl = NULL; gboolean res; tmpl = cogl_onscreen_template_new (swap_chain); /* XXX: I have some doubts that this is a good design. * * Conceptually should we be able to check an onscreen_template * without more details about the CoglDisplay configuration? */ res = cogl_renderer_check_onscreen_template (backend->cogl_renderer, tmpl, &internal_error); if (!res) goto error; - backend->cogl_display = cogl_display_new (backend->cogl_renderer, tmpl); - /* the display owns the template */ - cogl_object_unref (tmpl); + backend->cogl_display = cogl_display_new (backend->cogl_renderer, tmpl); } if (backend->cogl_display == NULL) goto error; #ifdef CLUTTER_HAS_WAYLAND_COMPOSITOR_SUPPORT cogl_wayland_display_set_compositor_display (backend->cogl_display, _wayland_compositor_display); #endif CLUTTER_NOTE (BACKEND, "Setting up the display"); if (!cogl_display_setup (backend->cogl_display, &internal_error)) goto error; CLUTTER_NOTE (BACKEND, "Creating the Cogl context"); backend->cogl_context = cogl_context_new (backend->cogl_display, &internal_error); if (backend->cogl_context == NULL) goto error; /* the display owns the renderer and the swap chain */ cogl_object_unref (backend->cogl_renderer); cogl_object_unref (swap_chain); return TRUE; error: if (backend->cogl_display != NULL) { cogl_object_unref (backend->cogl_display); backend->cogl_display = NULL; -- 2.26.2