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:
@@ -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);
|
CTX_py_state_pop(C, &self->py_state);
|
||||||
Py_CLEAR(self->py_state_context_dict);
|
Py_CLEAR(self->py_state_context_dict);
|
||||||
|
|
||||||
@@ -304,3 +309,11 @@ PyMethodDef BPY_rna_context_temp_override_method_def = {
|
|||||||
METH_VARARGS | METH_KEYWORDS,
|
METH_VARARGS | METH_KEYWORDS,
|
||||||
bpy_context_temp_override_doc,
|
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;
|
extern PyMethodDef BPY_rna_context_temp_override_method_def;
|
||||||
|
|
||||||
|
void bpy_rna_context_types_init(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -268,6 +268,8 @@ void BPY_rna_types_extend_capi(void)
|
|||||||
&RNA_WindowManager, pyrna_windowmanager_methods, pyrna_windowmanager_getset);
|
&RNA_WindowManager, pyrna_windowmanager_methods, pyrna_windowmanager_getset);
|
||||||
|
|
||||||
/* Context */
|
/* Context */
|
||||||
|
bpy_rna_context_types_init();
|
||||||
|
|
||||||
ARRAY_SET_ITEMS(pyrna_context_methods, BPY_rna_context_temp_override_method_def);
|
ARRAY_SET_ITEMS(pyrna_context_methods, BPY_rna_context_temp_override_method_def);
|
||||||
pyrna_struct_type_extend_capi(&RNA_Context, pyrna_context_methods, NULL);
|
pyrna_struct_type_extend_capi(&RNA_Context, pyrna_context_methods, NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user