[Spice-devel] [PATCH v2 1/4] spice-channel: Properly error out if reconnect fails

Frediano Ziglio fziglio at redhat.com
Wed Sep 26 10:04:02 UTC 2018


> 
> Hi,
> 
> On Tue, Sep 18, 2018 at 03:53:19AM -0400, Frediano Ziglio wrote:
> > > 
> > > From: Victor Toso <me at victortoso.com>
> > > 
> > > The channel_connect() function could fail leading to a spice-channel
> > > existing as zombie (its coroutine return soon after).
> > > 
> > > Check if channel_connect() fails and give a proper error signal to
> > > user when that happens.
> > > 
> > > Related: https://bugzilla.redhat.com/show_bug.cgi?id=1625550
> > > Signed-off-by: Victor Toso <victortoso at redhat.com>
> > > ---
> > >  src/spice-channel.c | 12 ++++++++----
> > >  1 file changed, 8 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/src/spice-channel.c b/src/spice-channel.c
> > > index 0a5437c..aa035e1 100644
> > > --- a/src/spice-channel.c
> > > +++ b/src/spice-channel.c
> > > @@ -2675,11 +2675,15 @@ cleanup:
> > >      if (c->state == SPICE_CHANNEL_STATE_RECONNECTING ||
> > >          c->state == SPICE_CHANNEL_STATE_SWITCHING) {
> > >          g_warn_if_fail(c->event == SPICE_CHANNEL_NONE);
> > > -        channel_connect(channel, c->tls);
> > > -        g_object_unref(channel);
> > > -    } else
> > > -        g_idle_add(spice_channel_delayed_unref, data);
> > > +        if (channel_connect(channel, c->tls)) {
> > > +            g_object_unref(channel);
> > > +            return NULL;
> > > +        }
> > > +
> > > +        c->event = SPICE_CHANNEL_ERROR_CONNECT;
> > > +    }
> > >  
> > > +    g_idle_add(spice_channel_delayed_unref, data);
> > >      /* Co-routine exits now - the SpiceChannel object may no longer
> > >      exist,
> > >         so don't do anything else now unless you like SEGVs */
> > 
> > Patch is good, this comment is now wrong here, channel (or
> > data) is still valid.
> 
> I think the comment is still right.
> 
> It says that user should not use the SpiceChannel as the
> coroutine is returning, the _may_ in "SpiceChannel object may no
> longer exist" is a reference to the delayed unref of the channel,
> no? Which happens above the comment now, instead of in the else
> {} as it was before.
> 
> So, I think it was true before and I don't think this patch
> changes it?
> 
> Note also that in case that channel_connect() succeeds, it
> happens with a connect_delayed() for this coroutine to return.
> 

Not strong about the command, but data/channel here is always
valid and the object is surely existing, g_idle_add just do
a schedule, if channel_connect succeeded this code is not
executed (this was the path leading to a not existing object).

> > Maybe
> >     g_idle_add(spice_channel_delayed_unref, channel);
> > 
> > is more readable (data == channel).
> 
> Yep, I agree. I'll change it a send all patches again as v3
> 
> Cheers!
> 
> > 
> > >      return NULL;
> > 

Frediano


More information about the Spice-devel mailing list