Blame SOURCES/0015-group-Free-group-if-returning-early.patch

79df40
From 12eefc7a5346ef9132afe1a3e929308f70cd5121 Mon Sep 17 00:00:00 2001
79df40
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
79df40
Date: Tue, 9 Jul 2019 11:17:18 +0200
79df40
Subject: [PATCH 15/28] group: Free group if returning early
79df40
79df40
If we get an error when fetching the window attributes, the group isn't ever
79df40
free'd, so use an autopointer instead, releasing the stolen one.
79df40
79df40
https://gitlab.gnome.org/GNOME/mutter/merge_requests/682
79df40
---
79df40
 src/x11/group.c | 4 ++--
79df40
 1 file changed, 2 insertions(+), 2 deletions(-)
79df40
79df40
diff --git a/src/x11/group.c b/src/x11/group.c
79df40
index 123b9e153..4fafa28eb 100644
79df40
--- a/src/x11/group.c
79df40
+++ b/src/x11/group.c
79df40
@@ -10,111 +10,111 @@
79df40
  * License, or (at your option) any later version.
79df40
  *
79df40
  * This program is distributed in the hope that it will be useful, but
79df40
  * WITHOUT ANY WARRANTY; without even the implied warranty of
79df40
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
79df40
  * General Public License for more details.
79df40
  *
79df40
  * You should have received a copy of the GNU General Public License
79df40
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
79df40
  */
79df40
 
79df40
 /**
79df40
  * SECTION:group
79df40
  * @title: MetaGroup
79df40
  * @short_description: Mutter window groups
79df40
  *
79df40
  */
79df40
 
79df40
 #include <config.h>
79df40
 #include <meta/util.h>
79df40
 #include "group-private.h"
79df40
 #include "group-props.h"
79df40
 #include "window-private.h"
79df40
 #include <meta/window.h>
79df40
 #include <X11/Xlib-xcb.h>
79df40
 
79df40
 static MetaGroup*
79df40
 meta_group_new (MetaDisplay *display,
79df40
                 Window       group_leader)
79df40
 {
79df40
-  MetaGroup *group;
79df40
+  g_autofree MetaGroup *group = NULL;
79df40
 #define N_INITIAL_PROPS 3
79df40
   Atom initial_props[N_INITIAL_PROPS];
79df40
   int i;
79df40
 
79df40
   g_assert (N_INITIAL_PROPS == (int) G_N_ELEMENTS (initial_props));
79df40
 
79df40
   group = g_new0 (MetaGroup, 1);
79df40
 
79df40
   group->display = display;
79df40
   group->windows = NULL;
79df40
   group->group_leader = group_leader;
79df40
   group->refcount = 1; /* owned by caller, hash table has only weak ref */
79df40
 
79df40
   xcb_connection_t *xcb_conn = XGetXCBConnection (display->xdisplay);
79df40
   xcb_generic_error_t *e;
79df40
   g_autofree xcb_get_window_attributes_reply_t *attrs =
79df40
     xcb_get_window_attributes_reply (xcb_conn,
79df40
                                      xcb_get_window_attributes (xcb_conn, group_leader),
79df40
                                      &e);
79df40
   if (e)
79df40
     return NULL;
79df40
 
79df40
   const uint32_t events[] = { attrs->your_event_mask | XCB_EVENT_MASK_PROPERTY_CHANGE };
79df40
   xcb_change_window_attributes (xcb_conn, group_leader,
79df40
                                 XCB_CW_EVENT_MASK, events);
79df40
 
79df40
   if (display->groups_by_leader == NULL)
79df40
     display->groups_by_leader = g_hash_table_new (meta_unsigned_long_hash,
79df40
                                                   meta_unsigned_long_equal);
79df40
 
79df40
   g_assert (g_hash_table_lookup (display->groups_by_leader, &group_leader) == NULL);
79df40
 
79df40
   g_hash_table_insert (display->groups_by_leader,
79df40
                        &group->group_leader,
79df40
                        group);
79df40
 
79df40
   /* Fill these in the order we want them to be gotten */
79df40
   i = 0;
79df40
   initial_props[i++] = display->atom_WM_CLIENT_MACHINE;
79df40
   initial_props[i++] = display->atom__NET_WM_PID;
79df40
   initial_props[i++] = display->atom__NET_STARTUP_ID;
79df40
   g_assert (N_INITIAL_PROPS == i);
79df40
 
79df40
   meta_group_reload_properties (group, initial_props, N_INITIAL_PROPS);
79df40
 
79df40
   meta_topic (META_DEBUG_GROUPS,
79df40
               "Created new group with leader 0x%lx\n",
79df40
               group->group_leader);
79df40
 
79df40
-  return group;
79df40
+  return g_steal_pointer (&group);
79df40
 }
79df40
 
79df40
 static void
79df40
 meta_group_unref (MetaGroup *group)
79df40
 {
79df40
   g_return_if_fail (group->refcount > 0);
79df40
 
79df40
   group->refcount -= 1;
79df40
   if (group->refcount == 0)
79df40
     {
79df40
       meta_topic (META_DEBUG_GROUPS,
79df40
                   "Destroying group with leader 0x%lx\n",
79df40
                   group->group_leader);
79df40
 
79df40
       g_assert (group->display->groups_by_leader != NULL);
79df40
 
79df40
       g_hash_table_remove (group->display->groups_by_leader,
79df40
                            &group->group_leader);
79df40
 
79df40
       /* mop up hash table, this is how it gets freed on display close */
79df40
       if (g_hash_table_size (group->display->groups_by_leader) == 0)
79df40
         {
79df40
           g_hash_table_destroy (group->display->groups_by_leader);
79df40
           group->display->groups_by_leader = NULL;
79df40
         }
79df40
 
79df40
       g_free (group->wm_client_machine);
79df40
       g_free (group->startup_id);
79df40
 
79df40
       g_free (group);
79df40
-- 
79df40
2.26.2
79df40