OK, thank you Paolo! I will write a char_unparent as your comment.

Wind Yu


------------------ 原始邮件 ------------------
发件人: "Paolo Bonzini" <pbonzini@redhat.com>;
发送时间: 2021年11月19日(星期五) 下午5:27
收件人: "Marc-André Lureau"<marcandre.lureau@redhat.com>;"ぷ风过无痕??"<787738581@qq.com>;
抄送: "qemu-devel"<qemu-devel@nongnu.org>;
主题: Re: Chardev: delete the QemuOpts reserved in vm_config_groups

On 11/8/21 09:46, Marc-André Lureau wrote:
>> +   QemuOpts *opts;
>>
>>       chr = qemu_chr_find(id);
>>       if (chr == NULL) {
>> @@ -1175,6 +1177,10 @@ void qmp_chardev_remove(const char *id, Error **errp)
>>           return;
>>       }
>>       object_unparent(OBJECT(chr));
>> +    /* delete the opts reserved in vm_config_groups list.  */
>> +    opts = qemu_opts_find(qemu_find_opts("chardev"), id);
>> +    if (opts)
>> +        qemu_opts_del(opts);
> That seems reasonable to me,
> Reviewed-by: Marc-André Lureau<marcandre.lureau@redhat.com>

I think it should be done instead in an unparent function, i.e. with
something like "oc->unparent = chr_unparent;" in char_class_init.
chr_unparent does the qemu_opts_find/qemu_opts_del.

Thanks,

Paolo