From: Marc-André Lureau Date: Wed, 11 Jul 2018 18:00:19 +0000 (+0200) Subject: chardev: unref if underlying chardev has no parent X-Git-Tag: v3.1.0-rc0~70^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=425d8a4e70f3946ac649925c4e3211906371ca6d;p=thirdparty%2Fqemu.git 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 Reviewed-by: Daniel P. Berrangé --- diff --git a/chardev/char-fe.c b/chardev/char-fe.c index f158f158f81..a8931f7afd2 100644 --- a/chardev/char-fe.c +++ b/chardev/char-fe.c @@ -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; }