mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-09 18:54:04 +02:00
Merge branch 'fdonotif-segfault-fix' into 'master'
gfdonotificationbackend: Fix possible invalid pointer in dbus callback See merge request GNOME/glib!90
This commit is contained in:
@@ -62,7 +62,6 @@ typedef struct
|
|||||||
GVariant *default_action_target;
|
GVariant *default_action_target;
|
||||||
} FreedesktopNotification;
|
} FreedesktopNotification;
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
freedesktop_notification_free (gpointer data)
|
freedesktop_notification_free (gpointer data)
|
||||||
{
|
{
|
||||||
@@ -76,6 +75,24 @@ freedesktop_notification_free (gpointer data)
|
|||||||
g_slice_free (FreedesktopNotification, n);
|
g_slice_free (FreedesktopNotification, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static FreedesktopNotification *
|
||||||
|
freedesktop_notification_new (GFdoNotificationBackend *backend,
|
||||||
|
const gchar *id,
|
||||||
|
GNotification *notification)
|
||||||
|
{
|
||||||
|
FreedesktopNotification *n;
|
||||||
|
|
||||||
|
n = g_slice_new0 (FreedesktopNotification);
|
||||||
|
n->backend = backend;
|
||||||
|
n->id = g_strdup (id);
|
||||||
|
n->notify_id = 0;
|
||||||
|
g_notification_get_default_action (notification,
|
||||||
|
&n->default_action,
|
||||||
|
&n->default_action_target);
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
static FreedesktopNotification *
|
static FreedesktopNotification *
|
||||||
g_fdo_notification_backend_find_notification (GFdoNotificationBackend *backend,
|
g_fdo_notification_backend_find_notification (GFdoNotificationBackend *backend,
|
||||||
const gchar *id)
|
const gchar *id)
|
||||||
@@ -319,8 +336,19 @@ notification_sent (GObject *source_object,
|
|||||||
val = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), result, &error);
|
val = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), result, &error);
|
||||||
if (val)
|
if (val)
|
||||||
{
|
{
|
||||||
|
GFdoNotificationBackend *backend = n->backend;
|
||||||
|
FreedesktopNotification *match;
|
||||||
|
|
||||||
g_variant_get (val, "(u)", &n->notify_id);
|
g_variant_get (val, "(u)", &n->notify_id);
|
||||||
g_variant_unref (val);
|
g_variant_unref (val);
|
||||||
|
|
||||||
|
match = g_fdo_notification_backend_find_notification_by_notify_id (backend, n->notify_id);
|
||||||
|
if (match != NULL)
|
||||||
|
{
|
||||||
|
backend->notifications = g_slist_remove (backend->notifications, match);
|
||||||
|
freedesktop_notification_free (match);
|
||||||
|
}
|
||||||
|
backend->notifications = g_slist_prepend (backend->notifications, n);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -331,9 +359,7 @@ notification_sent (GObject *source_object,
|
|||||||
warning_printed = TRUE;
|
warning_printed = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
n->backend->notifications = g_slist_remove (n->backend->notifications, n);
|
|
||||||
freedesktop_notification_free (n);
|
freedesktop_notification_free (n);
|
||||||
|
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -378,7 +404,7 @@ g_fdo_notification_backend_send_notification (GNotificationBackend *backend,
|
|||||||
GNotification *notification)
|
GNotification *notification)
|
||||||
{
|
{
|
||||||
GFdoNotificationBackend *self = G_FDO_NOTIFICATION_BACKEND (backend);
|
GFdoNotificationBackend *self = G_FDO_NOTIFICATION_BACKEND (backend);
|
||||||
FreedesktopNotification *n;
|
FreedesktopNotification *n, *tmp;
|
||||||
|
|
||||||
if (self->notify_subscription == 0)
|
if (self->notify_subscription == 0)
|
||||||
{
|
{
|
||||||
@@ -391,24 +417,11 @@ g_fdo_notification_backend_send_notification (GNotificationBackend *backend,
|
|||||||
notify_signal, backend, NULL);
|
notify_signal, backend, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
n = g_fdo_notification_backend_find_notification (self, id);
|
n = freedesktop_notification_new (self, id, notification);
|
||||||
if (n == NULL)
|
|
||||||
{
|
|
||||||
n = g_slice_new0 (FreedesktopNotification);
|
|
||||||
n->backend = self;
|
|
||||||
n->id = g_strdup (id);
|
|
||||||
n->notify_id = 0;
|
|
||||||
|
|
||||||
n->backend->notifications = g_slist_prepend (n->backend->notifications, n);
|
tmp = g_fdo_notification_backend_find_notification (self, id);
|
||||||
}
|
if (tmp)
|
||||||
else
|
n->notify_id = tmp->notify_id;
|
||||||
{
|
|
||||||
/* Only clear default action. All other fields are still valid */
|
|
||||||
g_clear_pointer (&n->default_action, g_free);
|
|
||||||
g_clear_pointer (&n->default_action_target, g_variant_unref);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_notification_get_default_action (notification, &n->default_action, &n->default_action_target);
|
|
||||||
|
|
||||||
call_notify (backend->dbus_connection, backend->application, n->notify_id, notification, notification_sent, n);
|
call_notify (backend->dbus_connection, backend->application, n->notify_id, notification, notification_sent, n);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user