Workaround crash generating Python API documentation

Avoid accessing freed memory from dynamically allocated EnumPropertyItem
arrays. Rely on the memory being held by the iterator which isn't the
case when it was converted to a tuple.
This commit is contained in:
Campbell Barton 2022-11-08 16:43:16 +11:00
parent 8f439bdc2d
commit 3c1fb9aea1
1 changed files with 5 additions and 1 deletions

View File

@ -286,7 +286,10 @@ class InfoPropertyRNA:
self.enum_pointer = 0
if self.type == "enum":
items = tuple(rna_prop.enum_items)
# WARNING: don't convert to a tuple as this causes dynamically allocated enums to access freed memory
# since freeing the iterator may free the memory used to store the internal `EnumPropertyItem` array.
# To support this properly RNA would have to support owning the dynamically allocated memory.
items = rna_prop.enum_items
items_static = tuple(rna_prop.enum_items_static)
self.enum_items[:] = [(item.identifier, item.name, item.description) for item in items]
self.is_enum_flag = rna_prop.is_enum_flag
@ -295,6 +298,7 @@ class InfoPropertyRNA:
item = (items_static or items)
if item:
self.enum_pointer = item[0].as_pointer()
del items, items_static, item
else:
self.is_enum_flag = False