[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 1/2] qom: Introduce object_property_try_add_child()
From: |
Auger Eric |
Subject: |
Re: [PATCH v2 1/2] qom: Introduce object_property_try_add_child() |
Date: |
Wed, 24 Jun 2020 19:03:35 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 |
Hi Paolo,
On 6/24/20 6:16 PM, Paolo Bonzini wrote:
> On 24/06/20 18:02, Auger Eric wrote:
>> Hi Paolo,
>>
>> On 6/24/20 4:17 PM, Auger Eric wrote:
>>> Hi Paolo,
>>>
>>> On 6/24/20 4:12 PM, Paolo Bonzini wrote:
>>>> On 24/06/20 14:43, Eric Auger wrote:
>>>>> + op = object_property_try_add(obj, name, type,
>>>>> object_get_child_property,
>>>>> + NULL, object_finalize_child_property,
>>>>> + child, errp);
>>>>> + if (!op) {
>>>>> + goto out;
>>>>> + }
>>>>> op->resolve = object_resolve_child_property;
>>>>> +out:
>>>>> object_ref(child);
>>>>> child->parent = obj;
>>>>> return op;
>>>>
>>>> I think if there's an error you need to return NULL without ref-ing
>>>> child, shouldn't you?
>>> hum yes you're fully right, the out label is badly placed.
>> Looks the unref is done in user_creatable_add_type() in case of error.
>
> There are two references involved:
>
> - a reference returned from object_new. user_creatable_add_type()
> passes it back to the caller. The object_unref() you found is done
> before returning NULL, because in that case nothing is being passed to
> the caller
>
> - a reference stored in child->parent. In case of error that reference
> is dropped with object_property_del before returning NULL.
> object_property_try_add_child must not store anything in child->parent
> in case of error, and therefore it need not add that reference either.
>
> I hope this is clearer.
Yes it helps. Thank you for the clarifications.
Eric
>
> Thanks,
>
> Paolo
>
>> Isn't it the corresponding one? Anyway I think it is better to avoid
>> getting the ref here as you suggest (and also free type) and don't unref
>> in user_creatable_add_type.
>>
>> Thanks
>>
>> Eric
>>>>
>>>> You can then add another test that object_property_add_child succeeds
>>>> after object_property_try_add_child fails.
>>> OK
>>>
>>> Thanks
>>>
>>> Eric
>>>>
>>>> Paolo
>>>>
>>
>
>
Re: [PATCH v2 0/2] Avoid abort on QMP attempt to add an object with duplicate id, no-reply, 2020/06/24