Richard W.M. Jones
2022-Oct-27 08:49 UTC
[Libguestfs] [nbdkit PATCH 2/4] server: Give client EOF when we are done writing
On Wed, Oct 26, 2022 at 05:18:00PM -0500, Eric Blake wrote:> - if (conn->sockin >= 0) > - closesocket (conn->sockin); > - if (conn->sockout >= 0 && conn->sockin != conn->sockout) > - closesocket (conn->sockout); > + if (conn->sockout >= 0 && how == SHUT_WR) { > + if (conn->sockin == conn->sockout) > + shutdown (conn->sockout, how); > + else > + closesocket (conn->sockout); > + conn->sockout = -1;Don't we leak conn->sockin, if how == SHUT_WR && conn->sockin == conn->sockout? Rich.> + } > + else { > + if (conn->sockin >= 0) > + closesocket (conn->sockin); > + if (conn->sockout >= 0 && conn->sockin != conn->sockout) > + closesocket (conn->sockout); > + } > } > diff --git a/server/crypto.c b/server/crypto.c > index 1f605083..72486bf8 100644 > --- a/server/crypto.c > +++ b/server/crypto.c > @@ -412,7 +412,7 @@ crypto_send (const void *vbuf, size_t len, int flags) > * close, so this function ignores errors. > */ > static void > -crypto_close (void) > +crypto_close (int how) > { > GET_CONN; > gnutls_session_t session = conn->crypto_session; > @@ -420,17 +420,21 @@ crypto_close (void) > > assert (session != NULL); > > - gnutls_transport_get_int2 (session, &sockin, &sockout); > + if (how == SHUT_WR) > + gnutls_bye (session, GNUTLS_SHUT_WR); > + else { > + gnutls_transport_get_int2 (session, &sockin, &sockout); > > - gnutls_bye (session, GNUTLS_SHUT_RDWR); > + gnutls_bye (session, GNUTLS_SHUT_RDWR); > > - if (sockin >= 0) > - closesocket (sockin); > - if (sockout >= 0 && sockin != sockout) > - closesocket (sockout); > + if (sockin >= 0) > + closesocket (sockin); > + if (sockout >= 0 && sockin != sockout) > + closesocket (sockout); > > - gnutls_deinit (session); > - conn->crypto_session = NULL; > + gnutls_deinit (session); > + conn->crypto_session = NULL; > + } > } > > #ifdef WIN32 > -- > 2.37.3 > > _______________________________________________ > Libguestfs mailing list > Libguestfs at redhat.com > https://listman.redhat.com/mailman/listinfo/libguestfs-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Eric Blake
2022-Oct-31 13:56 UTC
[Libguestfs] [nbdkit PATCH 2/4] server: Give client EOF when we are done writing
On Thu, Oct 27, 2022 at 09:49:52AM +0100, Richard W.M. Jones wrote:> On Wed, Oct 26, 2022 at 05:18:00PM -0500, Eric Blake wrote: > > - if (conn->sockin >= 0) > > - closesocket (conn->sockin); > > - if (conn->sockout >= 0 && conn->sockin != conn->sockout) > > - closesocket (conn->sockout); > > + if (conn->sockout >= 0 && how == SHUT_WR) { > > + if (conn->sockin == conn->sockout) > > + shutdown (conn->sockout, how); > > + else > > + closesocket (conn->sockout); > > + conn->sockout = -1; > > Don't we leak conn->sockin, if how == SHUT_WR && conn->sockin == conn->sockout?No, because any call with how==SHUT_WR will eventually be followed by another call with how==SHUT_RDWR, and it is the latter call which handles closing sockin.> > Rich. > > > + } > > + else { > > + if (conn->sockin >= 0) > > + closesocket (conn->sockin); > > + if (conn->sockout >= 0 && conn->sockin != conn->sockout) > > + closesocket (conn->sockout); > > + } > > }-- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org