chardev: unref if underlying chardev has no parent

It's possible to write code creating a chardev backend that is not
registered. When it is not user-created, it makes sense to keep it
hidden. Let the associated frontend destroy it also in this case.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
master
Marc-André Lureau 2018-07-11 20:00:19 +02:00
parent 43182856c5
commit 425d8a4e70
1 changed files with 6 additions and 1 deletions

View File

@ -235,7 +235,12 @@ void qemu_chr_fe_deinit(CharBackend *b, bool del)
d->backends[b->tag] = NULL;
}
if (del) {
object_unparent(OBJECT(b->chr));
Object *obj = OBJECT(b->chr);
if (obj->parent) {
object_unparent(obj);
} else {
object_unref(obj);
}
}
b->chr = NULL;
}