From 94bd5c731991a2523e6ee60fffe67030479e5340 Mon Sep 17 00:00:00 2001 From: Sebastian Keller Date: Thu, 13 Apr 2023 01:25:27 +0200 Subject: [PATCH] x11: Use Atoms when constructing a new MetaX11SelectionOutputStream This was pointlessly being converted between atom and string and back, which with the switch from gdk_x11_get_xatom_name() to XGetAtomName() also introduced a leak for every XGetAtomName() call. Fixes: e66f4396e ("x11: Avoid GDK API in X11 selections") Part-of: --- ...meta-x11-selection-output-stream-private.h | 8 +++---- src/x11/meta-x11-selection-output-stream.c | 16 +++++++------- src/x11/meta-x11-selection.c | 21 +++++++++++-------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/x11/meta-x11-selection-output-stream-private.h b/src/x11/meta-x11-selection-output-stream-private.h index 83390da48..41bedd9db 100644 --- a/src/x11/meta-x11-selection-output-stream-private.h +++ b/src/x11/meta-x11-selection-output-stream-private.h @@ -34,10 +34,10 @@ G_DECLARE_FINAL_TYPE (MetaX11SelectionOutputStream, GOutputStream * meta_x11_selection_output_stream_new (MetaX11Display *x11_display, Window window, - const char *selection, - const char *target, - const char *property, - const char *type, + Atom selection, + Atom target, + Atom property, + Atom type, int format, gulong timestamp); diff --git a/src/x11/meta-x11-selection-output-stream.c b/src/x11/meta-x11-selection-output-stream.c index 41a691c9a..c8b76b68c 100644 --- a/src/x11/meta-x11-selection-output-stream.c +++ b/src/x11/meta-x11-selection-output-stream.c @@ -657,10 +657,10 @@ meta_x11_selection_output_stream_xevent (MetaX11SelectionOutputStream *stream, GOutputStream * meta_x11_selection_output_stream_new (MetaX11Display *x11_display, Window requestor, - const char *selection, - const char *target, - const char *property, - const char *type, + Atom selection, + Atom target, + Atom property, + Atom type, int format, gulong timestamp) { @@ -675,10 +675,10 @@ meta_x11_selection_output_stream_new (MetaX11Display *x11_display, priv->x11_display = x11_display; priv->xwindow = requestor; - priv->xselection = XInternAtom (x11_display->xdisplay, selection, False); - priv->xtarget = XInternAtom (x11_display->xdisplay, target, False); - priv->xproperty = XInternAtom (x11_display->xdisplay, property, False); - priv->xtype = XInternAtom (x11_display->xdisplay, type, False); + priv->xselection = selection; + priv->xtarget = target; + priv->xproperty = property; + priv->xtype = type; priv->format = format; priv->timestamp = timestamp; diff --git a/src/x11/meta-x11-selection.c b/src/x11/meta-x11-selection.c index 4e96aecd5..0700fb506 100644 --- a/src/x11/meta-x11-selection.c +++ b/src/x11/meta-x11-selection.c @@ -248,11 +248,14 @@ meta_x11_selection_handle_selection_request (MetaX11Display *x11_display, return FALSE; } - output = meta_x11_selection_output_stream_new (x11_display, event->requestor, - XGetAtomName (xdisplay, event->selection), - XGetAtomName (xdisplay, event->target), - XGetAtomName (xdisplay, event->property), - "ATOM", 32, event->time); + output = meta_x11_selection_output_stream_new (x11_display, + event->requestor, + event->selection, + event->target, + event->property, + XInternAtom (xdisplay, "ATOM", False), + 32, + event->time); bytes = mimetypes_to_bytes (mimetypes, x11_display->xdisplay); g_list_free_full (mimetypes, g_free); @@ -284,10 +287,10 @@ meta_x11_selection_handle_selection_request (MetaX11Display *x11_display, { output = meta_x11_selection_output_stream_new (x11_display, event->requestor, - XGetAtomName (xdisplay, event->selection), - XGetAtomName (xdisplay, event->target), - XGetAtomName (xdisplay, event->property), - XGetAtomName (xdisplay, event->target), + event->selection, + event->target, + event->property, + event->target, 8, event->time); meta_selection_transfer_async (selection,