sound player: Don't unref undefined fields

If the sound player feature is disabled, none of those fields are
instantiated which causes the crash reported in #2451

Also switch to using g_clear_pointer while we are at it

Fixes https://gitlab.gnome.org/GNOME/mutter/-/issues/2451

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2706>
This commit is contained in:
Bilal Elmoussaoui 2022-11-22 12:05:27 +01:00
parent 2ae9d9ee50
commit 74bb480753

View File

@ -34,12 +34,12 @@
struct _MetaSoundPlayer struct _MetaSoundPlayer
{ {
GObject parent; GObject parent;
#ifdef HAVE_SOUND_PLAYER
GThreadPool *queue; GThreadPool *queue;
GSettings *settings; GSettings *settings;
#ifdef HAVE_SOUND_PLAYER
ca_context *context; ca_context *context;
#endif
uint32_t id_pool; uint32_t id_pool;
#endif
}; };
#ifdef HAVE_SOUND_PLAYER #ifdef HAVE_SOUND_PLAYER
@ -71,13 +71,12 @@ G_DEFINE_TYPE (MetaSoundPlayer, meta_sound_player, G_TYPE_OBJECT)
static void static void
meta_sound_player_finalize (GObject *object) meta_sound_player_finalize (GObject *object)
{ {
#ifdef HAVE_SOUND_PLAYER
MetaSoundPlayer *player = META_SOUND_PLAYER (object); MetaSoundPlayer *player = META_SOUND_PLAYER (object);
g_object_unref (player->settings); g_clear_object (&player->settings);
g_thread_pool_free (player->queue, FALSE, TRUE); g_thread_pool_free (player->queue, FALSE, TRUE);
g_clear_pointer (&player->context, ca_context_destroy);
#ifdef HAVE_SOUND_PLAYER
ca_context_destroy (player->context);
#endif #endif
G_OBJECT_CLASS (meta_sound_player_parent_class)->finalize (object); G_OBJECT_CLASS (meta_sound_player_parent_class)->finalize (object);