diff options
author | Campbell Barton <campbell@blender.org> | 2022-04-26 09:48:34 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-04-26 09:51:20 +0300 |
commit | 2492d9852bb33aa7209f0a297a117488b0a39cfd (patch) | |
tree | 655c1cd2e8060f83ea7b7c681edeec39833dc4d9 /source/blender/python | |
parent | e0e737b72babf128409e3ab87e50a390ff4501e1 (diff) |
Fix memory leak in Context.temp_override
Add missing check as the context override dict may have been copied
since it was assigned, also initialize the context manager with
PyType_Ready, while it didn't cause any errors - it's expected
that all types are initialized.
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/intern/bpy_rna_context.c | 13 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna_context.h | 2 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna_types_capi.c | 2 |
3 files changed, 17 insertions, 0 deletions
diff --git a/source/blender/python/intern/bpy_rna_context.c b/source/blender/python/intern/bpy_rna_context.c index 811552ce938..1d033fee026 100644 --- a/source/blender/python/intern/bpy_rna_context.c +++ b/source/blender/python/intern/bpy_rna_context.c @@ -143,6 +143,11 @@ static PyObject *bpy_rna_context_temp_override_exit(BPyContextTempOverride *self } } + /* A copy may have been made when writing context members, see #BPY_context_dict_clear_members */ + PyObject *context_dict_test = CTX_py_dict_get(C); + if (context_dict_test && (context_dict_test != self->py_state_context_dict)) { + Py_DECREF(context_dict_test); + } CTX_py_state_pop(C, &self->py_state); Py_CLEAR(self->py_state_context_dict); @@ -304,3 +309,11 @@ PyMethodDef BPY_rna_context_temp_override_method_def = { METH_VARARGS | METH_KEYWORDS, bpy_context_temp_override_doc, }; + +void bpy_rna_context_types_init(void) +{ + if (PyType_Ready(&BPyContextTempOverride_Type) < 0) { + BLI_assert_unreachable(); + return; + } +} diff --git a/source/blender/python/intern/bpy_rna_context.h b/source/blender/python/intern/bpy_rna_context.h index ddd328131e6..c69ac15a352 100644 --- a/source/blender/python/intern/bpy_rna_context.h +++ b/source/blender/python/intern/bpy_rna_context.h @@ -12,6 +12,8 @@ extern "C" { extern PyMethodDef BPY_rna_context_temp_override_method_def; +void bpy_rna_context_types_init(void); + #ifdef __cplusplus } #endif diff --git a/source/blender/python/intern/bpy_rna_types_capi.c b/source/blender/python/intern/bpy_rna_types_capi.c index 376195ab845..608692876d6 100644 --- a/source/blender/python/intern/bpy_rna_types_capi.c +++ b/source/blender/python/intern/bpy_rna_types_capi.c @@ -268,6 +268,8 @@ void BPY_rna_types_extend_capi(void) &RNA_WindowManager, pyrna_windowmanager_methods, pyrna_windowmanager_getset); /* Context */ + bpy_rna_context_types_init(); + ARRAY_SET_ITEMS(pyrna_context_methods, BPY_rna_context_temp_override_method_def); pyrna_struct_type_extend_capi(&RNA_Context, pyrna_context_methods, NULL); } |