qemu-e2k/include/qapi
Eric Blake 68ab47e4b4 qapi: Change visit_type_FOO() to no longer return partial objects
Returning a partial object on error is an invitation for a careless
caller to leak memory.  We already fixed things in an earlier
patch to guarantee NULL if visit_start fails ("qapi: Guarantee
NULL obj on input visitor callback error"), but that does not
help the case where visit_start succeeds but some other failure
happens before visit_end, such that we leak a partially constructed
object outside visit_type_FOO(). As no one outside the testsuite
was actually relying on these semantics, it is cleaner to just
document and guarantee that ALL pointer-based visit_type_FOO()
functions always leave a safe value in *obj during an input visitor
(either the new object on success, or NULL if an error is
encountered), so callers can now unconditionally use
qapi_free_FOO() to clean up regardless of whether an error occurred.

The decision is done by adding visit_is_input(), then updating the
generated code to check if additional cleanup is needed based on
the type of visitor in use.

Note that we still leave *obj unchanged after a scalar-based
visit_type_FOO(); I did not feel like auditing all uses of
visit_type_Enum() to see if the callers would tolerate a specific
sentinel value (not to mention having to decide whether it would
be better to use 0 or ENUM__MAX as that sentinel).

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1461879932-9020-25-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-05-12 09:47:55 +02:00
..
qmp qmp: Drop dead command->type 2016-05-12 09:47:54 +02:00
dealloc-visitor.h qapi: Document visitor interfaces, add assertions 2016-05-12 09:47:54 +02:00
error.h include/qemu/osdep.h: Don't include qapi/error.h 2016-03-22 22:20:15 +01:00
opts-visitor.h qapi: Simplify semantics of visit_next_list() 2016-05-12 09:47:55 +02:00
qmp-event.h include: Clean up includes 2016-02-23 12:43:05 +00:00
qmp-input-visitor.h qapi: Consolidate QMP input visitor creation 2016-05-12 09:47:54 +02:00
qmp-output-visitor.h
string-input-visitor.h qapi: Simplify semantics of visit_next_list() 2016-05-12 09:47:55 +02:00
string-output-visitor.h qapi: Simplify semantics of visit_next_list() 2016-05-12 09:47:55 +02:00
util.h qom: Make enum string tables const-correct 2015-06-19 18:42:18 +02:00
visitor-impl.h qapi: Simplify semantics of visit_next_list() 2016-05-12 09:47:55 +02:00
visitor.h qapi: Change visit_type_FOO() to no longer return partial objects 2016-05-12 09:47:55 +02:00