mirror of
https://github.com/qemu/qemu.git
synced 2025-08-14 11:43:46 +00:00
qapi: allow freeing partially-allocated objects
Objects going through the dealloc visitor can be only partially allocated. Detect the situation and avoid a segfault. This also helps with the input visitor, when there are errors. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
This commit is contained in:
parent
b6f0474fc0
commit
69b50071d8
@ -65,6 +65,9 @@ def generate_visit_struct(name, members):
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(name)s), errp);
|
visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(name)s), errp);
|
||||||
|
if (obj && !*obj) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
''',
|
''',
|
||||||
name=name)
|
name=name)
|
||||||
push_indent()
|
push_indent()
|
||||||
@ -72,6 +75,7 @@ def generate_visit_struct(name, members):
|
|||||||
pop_indent()
|
pop_indent()
|
||||||
|
|
||||||
ret += mcgen('''
|
ret += mcgen('''
|
||||||
|
end:
|
||||||
visit_end_struct(m, errp);
|
visit_end_struct(m, errp);
|
||||||
}
|
}
|
||||||
''')
|
''')
|
||||||
@ -122,6 +126,9 @@ def generate_visit_union(name, members):
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(name)s), &err);
|
visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(name)s), &err);
|
||||||
|
if (obj && !*obj) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
visit_type_%(name)sKind(m, &(*obj)->kind, "type", &err);
|
visit_type_%(name)sKind(m, &(*obj)->kind, "type", &err);
|
||||||
if (err) {
|
if (err) {
|
||||||
error_propagate(errp, err);
|
error_propagate(errp, err);
|
||||||
|
Loading…
Reference in New Issue
Block a user