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>
This commit is contained in:
Marc-André Lureau 2018-07-11 20:00:19 +02:00
parent 43182856c5
commit 425d8a4e70

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;
}