From ccb16c42a3b83d92c0d9a64c09e6ede8da32759f Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Mon, 19 Feb 2018 19:31:47 -0500 Subject: [PATCH] qapi: Test failure in middle of array parse Our generated list visitors have the same problem as has been mentioned elsewhere (see commit 2f52e20): they allocate data even on failure. An upcoming patch will correct things to provide saner guarantees, but first we need to expose the behavior in the testsuite to ensure we aren't introducing any memory usage bugs. There are more test cases throughout the test-qmp-input-* tests that already deal with partial allocation; a later commit will clean up all visit_type_FOO(), without marking all of the tests with FIXME at this time. Backports commit dd5ee2c2d3e3a17647ddd9bfa97935b8cb5dfa40 from qemu --- qemu/scripts/qapi-visit.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qemu/scripts/qapi-visit.py b/qemu/scripts/qapi-visit.py index c2998e41..44316ade 100644 --- a/qemu/scripts/qapi-visit.py +++ b/qemu/scripts/qapi-visit.py @@ -135,6 +135,10 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error def gen_visit_list(name, element_type): + # FIXME: if *obj is NULL on entry, and the first visit_next_list() + # assigns to *obj, while a later one fails, we should clean up *obj + # rather than leaving it non-NULL. As currently written, the caller must + # call qapi_free_FOOList() to avoid a memory leak of the partial FOOList. return mcgen(''' void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error **errp)