On 28/07/2016 16:37, marcandre.lur...@redhat.com wrote: > From: Marc-André Lureau <marcandre.lur...@redhat.com> > > chr_disconnect callback is used to cleanup server socket peer. This > removes some leaks when the chardev is freed. > > Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com> > --- > qemu-char.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/qemu-char.c b/qemu-char.c > index e4b8448..6ed6dd6 100644 > --- a/qemu-char.c > +++ b/qemu-char.c > @@ -4031,6 +4031,7 @@ static void qemu_chr_free_common(CharDriverState *chr) > > void qemu_chr_free(CharDriverState *chr) > { > + qemu_chr_disconnect(chr); > if (chr->chr_close) { > chr->chr_close(chr); > } >
The patch, as is, would cause for example two calls to qemu_chr_be_event(chr, CHR_EVENT_CLOSED). It's also unnecessary to set up a watch on s->listen_ioc and to call qemu_chr_socket_restart_timer. I think the right fix is to extract the relevant parts of tcp_chr_disconnect into a new function (e.g. tcp_chr_free_connection) and call the function from tcp_chr_close. Paolo