From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47712) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUyAB-0002n5-LV for qemu-devel@nongnu.org; Wed, 03 Aug 2016 11:33:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bUyA6-0001fQ-Jk for qemu-devel@nongnu.org; Wed, 03 Aug 2016 11:32:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48958) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUyA6-0001eq-EC for qemu-devel@nongnu.org; Wed, 03 Aug 2016 11:32:50 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5CEDF8111C for ; Wed, 3 Aug 2016 15:32:48 +0000 (UTC) References: <20160803145541.15355-1-marcandre.lureau@redhat.com> <20160803145541.15355-20-marcandre.lureau@redhat.com> From: Paolo Bonzini Message-ID: Date: Wed, 3 Aug 2016 17:32:44 +0200 MIME-Version: 1.0 In-Reply-To: <20160803145541.15355-20-marcandre.lureau@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH for-2.7 v3 19/36] char: free the tcp connection data when closing List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: marcandre.lureau@redhat.com, qemu-devel@nongnu.org On 03/08/2016 16:55, marcandre.lureau@redhat.com wrote: > @@ -2851,11 +2851,6 @@ static void tcp_chr_disconnect(CharDriverState *= chr) > return; > } > =20 > - s->connected =3D 0; > - if (s->listen_ioc) { > - s->listen_tag =3D qio_channel_add_watch( > - QIO_CHANNEL(s->listen_ioc), G_IO_IN, tcp_chr_accept, chr, = NULL); > - } > tcp_set_msgfds(chr, NULL, 0); > remove_fd_in_watch(chr); > object_unref(OBJECT(s->sioc)); > @@ -2863,6 +2858,24 @@ static void tcp_chr_disconnect(CharDriverState *= chr) > object_unref(OBJECT(s->ioc)); > s->ioc =3D NULL; > g_free(chr->filename); > + chr->filename =3D NULL; > + s->connected =3D 0; > +} > + > +static void tcp_chr_disconnect(CharDriverState *chr) > +{ > + TCPCharDriver *s =3D chr->opaque; > + > + if (!s->connected) { > + return; > + } > + > + tcp_chr_free_connection(chr); > + > + if (s->listen_ioc) { > + s->listen_tag =3D qio_channel_add_watch( > + QIO_CHANNEL(s->listen_ioc), G_IO_IN, tcp_chr_accept, chr, = NULL); > + } I think if (s->read_msgfds_num) { for (i =3D 0; i < s->read_msgfds_num; i++) { close(s->read_msgfds[i]); } g_free(s->read_msgfds); } should be moved from tcp_chr_close to tcp_chr_free_connection. The following parts of tcp_chr_close instead are now duplicate, and can be removed: remove_fd_in_watch(chr); if (s->ioc) { object_unref(OBJECT(s->ioc)); } if (s->write_msgfds_num) { g_free(s->write_msgfds); } are now duplicate and can be removed. Finally, since you're at it, here in tcp_set_msgfds: /* clear old pending fd array */ g_free(s->write_msgfds); s->write_msgfds =3D NULL; it's best to add a s->write_msgfds_num =3D 0. Thanks, Paolo