diff mbox series

[v2,01/15] chardev: fix leak in tcp_chr_telnet_init_io()

Message ID 20180301084438.13594-2-peterx@redhat.com
State New
Headers show
Series qio: general non-default GMainContext support | expand

Commit Message

Peter Xu March 1, 2018, 8:44 a.m. UTC
Need to free TCPChardevTelnetInit when session established.

Since at it, switch to use G_SOURCE_* macros.

Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
 chardev/char-socket.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Paolo Bonzini March 1, 2018, 5:39 p.m. UTC | #1
On 01/03/2018 09:44, Peter Xu wrote:
> Need to free TCPChardevTelnetInit when session established.
> 
> Since at it, switch to use G_SOURCE_* macros.
> 
> Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  chardev/char-socket.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/chardev/char-socket.c b/chardev/char-socket.c
> index bdd6cff5f6..43a2cc2c1c 100644
> --- a/chardev/char-socket.c
> +++ b/chardev/char-socket.c
> @@ -591,19 +591,23 @@ static gboolean tcp_chr_telnet_init_io(QIOChannel *ioc,
>              ret = 0;
>          } else {
>              tcp_chr_disconnect(init->chr);
> -            return FALSE;
> +            goto end;
>          }
>      }
>      init->buflen -= ret;
>  
>      if (init->buflen == 0) {
>          tcp_chr_connect(init->chr);
> -        return FALSE;
> +        goto end;
>      }
>  
>      memmove(init->buf, init->buf + ret, init->buflen);
>  
> -    return TRUE;
> +    return G_SOURCE_CONTINUE;
> +
> +end:
> +    g_free(init);
> +    return G_SOURCE_REMOVE;
>  }
>  
>  static void tcp_chr_telnet_init(Chardev *chr)
> 

Queued, thanks (but it's okay if you post it again in v3, because I'm
not sure I'll be able to send a pull request tomorrow).

Paolo
Peter Xu March 2, 2018, 3:46 a.m. UTC | #2
On Thu, Mar 01, 2018 at 06:39:34PM +0100, Paolo Bonzini wrote:
> On 01/03/2018 09:44, Peter Xu wrote:
> > Need to free TCPChardevTelnetInit when session established.
> > 
> > Since at it, switch to use G_SOURCE_* macros.
> > 
> > Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
> > Signed-off-by: Peter Xu <peterx@redhat.com>
> > ---
> >  chardev/char-socket.c | 10 +++++++---
> >  1 file changed, 7 insertions(+), 3 deletions(-)
> > 
> > diff --git a/chardev/char-socket.c b/chardev/char-socket.c
> > index bdd6cff5f6..43a2cc2c1c 100644
> > --- a/chardev/char-socket.c
> > +++ b/chardev/char-socket.c
> > @@ -591,19 +591,23 @@ static gboolean tcp_chr_telnet_init_io(QIOChannel *ioc,
> >              ret = 0;
> >          } else {
> >              tcp_chr_disconnect(init->chr);
> > -            return FALSE;
> > +            goto end;
> >          }
> >      }
> >      init->buflen -= ret;
> >  
> >      if (init->buflen == 0) {
> >          tcp_chr_connect(init->chr);
> > -        return FALSE;
> > +        goto end;
> >      }
> >  
> >      memmove(init->buf, init->buf + ret, init->buflen);
> >  
> > -    return TRUE;
> > +    return G_SOURCE_CONTINUE;
> > +
> > +end:
> > +    g_free(init);
> > +    return G_SOURCE_REMOVE;
> >  }
> >  
> >  static void tcp_chr_telnet_init(Chardev *chr)
> > 
> 
> Queued, thanks (but it's okay if you post it again in v3, because I'm
> not sure I'll be able to send a pull request tomorrow).

Sure, thanks.

I believe this is an equivalent "r-b" if I repost. :)
diff mbox series

Patch

diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index bdd6cff5f6..43a2cc2c1c 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -591,19 +591,23 @@  static gboolean tcp_chr_telnet_init_io(QIOChannel *ioc,
             ret = 0;
         } else {
             tcp_chr_disconnect(init->chr);
-            return FALSE;
+            goto end;
         }
     }
     init->buflen -= ret;
 
     if (init->buflen == 0) {
         tcp_chr_connect(init->chr);
-        return FALSE;
+        goto end;
     }
 
     memmove(init->buf, init->buf + ret, init->buflen);
 
-    return TRUE;
+    return G_SOURCE_CONTINUE;
+
+end:
+    g_free(init);
+    return G_SOURCE_REMOVE;
 }
 
 static void tcp_chr_telnet_init(Chardev *chr)