From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56950) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUCeI-0000Dn-AE for qemu-devel@nongnu.org; Mon, 01 Aug 2016 08:48:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bUCeD-0000Vm-9g for qemu-devel@nongnu.org; Mon, 01 Aug 2016 08:48:49 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:34346) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUCeD-0000Vi-2H for qemu-devel@nongnu.org; Mon, 01 Aug 2016 08:48:45 -0400 Received: by mail-wm0-x243.google.com with SMTP id q128so26049332wma.1 for ; Mon, 01 Aug 2016 05:48:44 -0700 (PDT) Sender: Paolo Bonzini References: <20160728143808.13707-1-marcandre.lureau@redhat.com> <20160728143808.13707-20-marcandre.lureau@redhat.com> From: Paolo Bonzini Message-ID: <3df5424c-8da4-8a8d-5bbc-dcc4e9c8270a@redhat.com> Date: Mon, 1 Aug 2016 14:48:40 +0200 MIME-Version: 1.0 In-Reply-To: <20160728143808.13707-20-marcandre.lureau@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH v2 19/37] char: disconnect peer when qemu_chr_free() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: marcandre.lureau@redhat.com, qemu-devel@nongnu.org On 28/07/2016 16:37, marcandre.lureau@redhat.com wrote: > From: Marc-André Lureau > > 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 > --- > 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