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