From 3ce6b85a04d5dacf27a228e002a4f301fc88abfd Mon Sep 17 00:00:00 2001 From: Saverio Miroddi Date: Tue, 21 Jul 2026 13:09:53 +0200 Subject: daemon: Fix GetCapabilities memory leak g_variant_dup_strv() allocates a vector and duplicates every string. The generated completion helper copies that vector into the outgoing GVariant, leaving the duplicated input unowned. AddressSanitizer reports 360 direct bytes and 420 indirect bytes leaked after five calls. Pass the constant capability list directly to the helper instead. This avoids the temporary allocations while leaving the returned capabilities unchanged. Signed-off-by: Saverio Miroddi --- src/daemon/daemon.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 4ff9ea9..7f4516f 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c @@ -1943,25 +1943,22 @@ static gboolean notify_daemon_close_notification_handler(NotifyDaemonNotificatio static gboolean notify_daemon_get_capabilities( NotifyDaemonNotifications *object, GDBusMethodInvocation *invocation) { - GVariantBuilder *builder; - GVariant *value; - - builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); - g_variant_builder_add (builder, "s", "actions"); - g_variant_builder_add (builder, "s", "action-icons"); - g_variant_builder_add (builder, "s", "body"); - g_variant_builder_add (builder, "s", "body-hyperlinks"); - g_variant_builder_add (builder, "s", "body-markup"); - g_variant_builder_add (builder, "s", "icon-static"); - g_variant_builder_add (builder, "s", "sound"); - g_variant_builder_add (builder, "s", "persistence"); - value = g_variant_new ("as", builder); - g_variant_builder_unref (builder); + static const gchar *const capabilities[] = { + "actions", + "action-icons", + "body", + "body-hyperlinks", + "body-markup", + "icon-static", + "sound", + "persistence", + NULL + }; + notify_daemon_notifications_complete_get_capabilities ( object, invocation, - (const gchar* const *)g_variant_dup_strv (value, NULL)); - g_variant_unref (value); + capabilities); return TRUE; } -- cgit v1.2.1