Received: from eggs.gnu.org ([2001:4830:134:3::10]:47470) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDWGq-0006aA-Mt for qemu-devel@nongnu.org; Thu, 16 Jun 2016 08:19:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bDWGk-0007h2-Kl for qemu-devel@nongnu.org; Thu, 16 Jun 2016 08:19:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53728) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDWGk-0007gQ-EP for qemu-devel@nongnu.org; Thu, 16 Jun 2016 08:19:34 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 ED1B080E4A for ; Thu, 16 Jun 2016 12:19:33 +0000 (UTC) References: <1466075835-28494-1-git-send-email-marcandre.lureau@redhat.com> <1466075835-28494-2-git-send-email-marcandre.lureau@redhat.com> From: Paolo Bonzini Message-ID: Date: Thu, 16 Jun 2016 14:19:30 +0200 MIME-Version: 1.0 In-Reply-To: <1466075835-28494-2-git-send-email-marcandre.lureau@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 1/3] char: clean up remaining chardevs when leaving List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: marcandre.lureau@redhat.com, qemu-devel@nongnu.org On 16/06/2016 13:17, marcandre.lureau@redhat.com wrote: > From: Marc-Andr=C3=A9 Lureau >=20 > This helps to remove various chardev resources leaks when leaving qemu. >=20 > Signed-off-by: Marc-Andr=C3=A9 Lureau > --- > include/sysemu/char.h | 7 +++++++ > qemu-char.c | 9 +++++++++ > vl.c | 1 + > 3 files changed, 17 insertions(+) >=20 > diff --git a/include/sysemu/char.h b/include/sysemu/char.h > index 372a6fd..8954be1 100644 > --- a/include/sysemu/char.h > +++ b/include/sysemu/char.h > @@ -382,6 +382,13 @@ void qemu_chr_be_write_impl(CharDriverState *s, ui= nt8_t *buf, int len); > */ > void qemu_chr_be_event(CharDriverState *s, int event); > =20 > +/** > + * @qemu_chr_cleanup: > + * > + * Delete all chardevs (when leaving qemu) > + */ > +void qemu_chr_cleanup(void); > + > void qemu_chr_add_handlers(CharDriverState *s, > IOCanReadHandler *fd_can_read, > IOReadHandler *fd_read, > diff --git a/qemu-char.c b/qemu-char.c > index b13ecbb..bf098a1 100644 > --- a/qemu-char.c > +++ b/qemu-char.c > @@ -4088,6 +4088,15 @@ CharDriverState *qemu_chr_find(const char *name) > return NULL; > } > =20 > +void qemu_chr_cleanup(void) > +{ > + CharDriverState *chr; > + > + QTAILQ_FOREACH(chr, &chardevs, next) { > + qemu_chr_delete(chr); > + } > +} > + > QemuOptsList qemu_chardev_opts =3D { > .name =3D "chardev", > .implied_opt_name =3D "backend", > diff --git a/vl.c b/vl.c > index 45eff56..ac92b1d 100644 > --- a/vl.c > +++ b/vl.c > @@ -4628,6 +4628,7 @@ int main(int argc, char **argv, char **envp) > #ifdef CONFIG_TPM > tpm_cleanup(); > #endif > + qemu_chr_cleanup(); Given the amount of exit(1) calls surviving in QEMU, it's probably better to use atexit here. Paolo > return 0; > } >=20