On 16/06/2016 13:17, [email protected] wrote: > From: Marc-André Lureau <[email protected]> > > This helps to remove various chardev resources leaks when leaving qemu. > > Signed-off-by: Marc-André Lureau <[email protected]> > --- > include/sysemu/char.h | 7 +++++++ > qemu-char.c | 9 +++++++++ > vl.c | 1 + > 3 files changed, 17 insertions(+) > > 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, uint8_t > *buf, int len); > */ > void qemu_chr_be_event(CharDriverState *s, int event); > > +/** > + * @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; > } > > +void qemu_chr_cleanup(void) > +{ > + CharDriverState *chr; > + > + QTAILQ_FOREACH(chr, &chardevs, next) { > + qemu_chr_delete(chr); > + } > +} > + > QemuOptsList qemu_chardev_opts = { > .name = "chardev", > .implied_opt_name = "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; > } >
