qom: Fix invalid error check in property_get_str()

When a function returns a null pointer on error and only on error, you
can do

if (!foo(foos, errp)) {
... handle error ...
}

instead of the more cumbersome

Error *err = NULL;

if (!foo(foos, &err)) {
error_propagate(errp, err);
... handle error ...
}

A StringProperty's getter, however, may return null on success! We
then fail to call visit_type_str().

Screwed up in 6a146eb, v1.1.

Fails tests/qom-test in my current, heavily hacked QAPI branch. No
reproducer for master known (but I didn't look hard).

Backports commit a479b21c111a87a50203a7413c4e5ec419fc88dd from qemu
This commit is contained in:
Markus Armbruster 2018-02-14 19:22:46 -05:00 committed by Lioncash
parent f0bf3c2e3b
commit 1b38f5208f
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -1359,12 +1359,16 @@ static void property_get_str(struct uc_struct *uc, Object *obj, Visitor *v, void
{
StringProperty *prop = opaque;
char *value;
Error *err = NULL;
value = prop->get(uc, obj, errp);
if (value) {
visit_type_str(v, &value, name, errp);
g_free(value);
value = prop->get(uc, obj, &err);
if (err) {
error_propagate(errp, err);
return;
}
visit_type_str(v, &value, name, errp);
g_free(value);
}
static int property_set_str(struct uc_struct *uc, Object *obj, Visitor *v, void *opaque,