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.
This commit is contained in:
parent
e0e737b72b
commit
2492d9852b
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue