qemu-e2k/scripts/qapi
Markus Armbruster cbf97d5b79 qapi: Fix visit_type_STRUCT() not to fail for null object
To make deallocating partially constructed objects work, the
visit_type_STRUCT() need to succeed without doing anything when passed
a null object.

Commit cdd2b228b9 "qapi: Smooth visitor error checking in generated
code" broke that.  To reproduce, run tests/test-qobject-input-visitor
with AddressSanitizer:

    ==4353==ERROR: LeakSanitizer: detected memory leaks

    Direct leak of 16 byte(s) in 1 object(s) allocated from:
	#0 0x7f192d0c5d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
	#1 0x7f192cd21b10 in g_malloc0 (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x51b10)
	#2 0x556725f6bbee in visit_next_list qapi/qapi-visit-core.c:86
	#3 0x556725f49e15 in visit_type_UserDefOneList tests/test-qapi-visit.c:474
	#4 0x556725f4489b in test_visitor_in_fail_struct_in_list tests/test-qobject-input-visitor.c:1086
	#5 0x7f192cd42f29  (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x72f29)

    SUMMARY: AddressSanitizer: 16 byte(s) leaked in 1 allocation(s).

Test case /visitor/input/fail/struct-in-list feeds a list with a bad
element to the QObject input visitor.  Visiting that element duly
fails, and aborts the visit with the list only partially constructed:
the faulty object is null.  Cleaning up the partially constructed list
visits that null object, fails, and aborts the visit before the list
node gets freed.

Fix the the generated visit_type_STRUCT() to succeed for null objects.

Fixes: cdd2b228b9
Reported-by: Li Qiang <liq3ea@163.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200716150617.4027356-1-armbru@redhat.com>
Tested-by: Li Qiang <liq3ea@gmail.com>
Reviewed-by: Li Qiang <liq3ea@gmail.com>
2020-07-21 14:38:23 +02:00
..
__init__.py qapi-gen: New common driver for code and doc generators 2018-03-02 13:14:09 -06:00
commands.py qapi: Smooth visitor error checking in generated code 2020-07-10 15:18:08 +02:00
common.py qapi: Drop conditionals for Python 2 2020-03-05 09:24:11 +01:00
doc.py qapi: Consistently put @features parameter right after @ifcond 2020-03-17 19:58:34 +01:00
error.py qapi: Use super() now we have Python 3 2020-03-05 09:24:11 +01:00
events.py qapi: Add feature flags to remaining definitions 2020-03-17 19:58:34 +01:00
expr.py qapi: Add feature flags to struct members 2020-03-17 21:25:47 +01:00
gen.py qemu-storage-daemon: Add --monitor option 2020-03-06 17:21:28 +01:00
introspect.py qapi: Add feature flags to struct members 2020-03-17 21:25:47 +01:00
parser.py qapi: Brush off some (py)lint 2020-03-05 09:24:11 +01:00
schema.py qapi: New special feature flag "deprecated" 2020-03-17 21:42:47 +01:00
source.py qapi: Inheriting from object is pointless with Python 3, drop 2020-03-05 09:24:11 +01:00
types.py qapi: Consistently put @features parameter right after @ifcond 2020-03-17 19:58:34 +01:00
visit.py qapi: Fix visit_type_STRUCT() not to fail for null object 2020-07-21 14:38:23 +02:00