qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: marcandre.lureau@redhat.com
Cc: qemu-devel@nongnu.org, Stefan Weil <sw@weilnetz.de>,
	Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: [PATCH 3/3] ui/dbus: fix passing SOCKET to GSocket API & leak
Date: Mon, 20 Mar 2023 12:17:06 +0000	[thread overview]
Message-ID: <ZBhOwnsGyZ0cV5rI@redhat.com> (raw)
In-Reply-To: <20230320111412.1516419-4-marcandre.lureau@redhat.com>

On Mon, Mar 20, 2023 at 03:14:12PM +0400, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> -display dbus is not currently available to win32 users, so it's not
> considered a regression.
> 
> Note also the close() leak fix in case of error.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  ui/dbus.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/ui/dbus.c b/ui/dbus.c
> index 0513de9918..5389ac493f 100644
> --- a/ui/dbus.c
> +++ b/ui/dbus.c
> @@ -304,9 +304,17 @@ dbus_display_add_client(int csock, Error **errp)
>          g_cancellable_cancel(dbus_display->add_client_cancellable);
>      }
>  
> +#ifdef WIN32
> +    csock = qemu_close_to_socket(csock);
> +#endif

Happens to work because 'int' and 'SOCKET' are the same, but I feel
like this is confusing to overload one variable for two different
purposes. This confusing code pattern is the only reason why the
method in patch 1 needs to return SOCKET. 

>      socket = g_socket_new_from_fd(csock, &err);
>      if (!socket) {
>          error_setg(errp, "Failed to setup D-Bus socket: %s", err->message);
> +#ifdef WIN32
> +        closesocket(csock);
> +#else
> +        close(csock);
> +#endif

IMHO it would be clearer to write it as

  #ifdef WIN32
  socket = g_socket_new_from_fd(_get_osfhandle(csock), &err);
  #else
  socket = g_socket_new_from_fd(csock, &err);
  #endif

  if (!socket) {
     error_setg(errp, "Failed to setup D-Bus socket: %s", err->message);
     close(csock);
     return ...
  }

  #ifdef WIN32
  /* socket owns the SOCKET handle now, so release our osf handle */
  qemu_close_socket_osfhandle(csock);
  #endif

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



      reply	other threads:[~2023-03-20 12:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-20 11:14 [PATCH 0/3] Fix Spice regression on win32 marcandre.lureau
2023-03-20 11:14 ` [PATCH 1/3] win32: add qemu_close_to_socket() marcandre.lureau
2023-03-20 12:10   ` Daniel P. Berrangé
2023-03-20 11:14 ` [PATCH 2/3] ui/spice: fix SOCKET handling regression marcandre.lureau
2023-03-20 12:10   ` Daniel P. Berrangé
2023-03-20 11:14 ` [PATCH 3/3] ui/dbus: fix passing SOCKET to GSocket API & leak marcandre.lureau
2023-03-20 12:17   ` Daniel P. Berrangé [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZBhOwnsGyZ0cV5rI@redhat.com \
    --to=berrange@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sw@weilnetz.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).