1
1

Python: clear Py-driver variables on exit

These kinds of leaks are relatively harmless, it reduces the number of
un-freed data reported by valgrind on exit.
This commit is contained in:
2022-07-07 12:30:45 +10:00
parent 5c790fd52b
commit 83c0f6ac37
3 changed files with 22 additions and 8 deletions

View File

@@ -69,6 +69,11 @@ void BPY_modules_load_user(struct bContext *C);
void BPY_app_handlers_reset(bool do_all);
/**
* Run on exit to free any cached data.
*/
void BPY_driver_exit(void);
/**
* Update function, it gets rid of python-drivers global dictionary: `bpy.app.driver_namespace`,
* forcing #BPY_driver_exec to recreate it. Use this when loading a new `.blend` file

View File

@@ -233,15 +233,8 @@ static void bpy_pydriver_namespace_update_depsgraph(struct Depsgraph *depsgraph)
}
}
void BPY_driver_reset(void)
void BPY_driver_exit(void)
{
PyGILState_STATE gilstate;
const bool use_gil = true; /* !PyC_IsInterpreterActive(); */
if (use_gil) {
gilstate = PyGILState_Ensure();
}
if (bpy_pydriver_Dict) { /* Free the global dict used by python-drivers. */
PyDict_Clear(bpy_pydriver_Dict);
Py_DECREF(bpy_pydriver_Dict);
@@ -261,6 +254,19 @@ void BPY_driver_reset(void)
/* Freed when clearing driver dictionary. */
g_pydriver_state_prev.self = NULL;
g_pydriver_state_prev.depsgraph = NULL;
}
void BPY_driver_reset(void)
{
PyGILState_STATE gilstate;
const bool use_gil = true; /* !PyC_IsInterpreterActive(); */
if (use_gil) {
gilstate = PyGILState_Ensure();
}
/* Currently exit/reset are practically the same besides the GIL check. */
BPY_driver_exit();
if (use_gil) {
PyGILState_Release(gilstate);

View File

@@ -512,6 +512,9 @@ void BPY_python_end(void)
/* finalizing, no need to grab the state, except when we are a module */
gilstate = PyGILState_Ensure();
/* Frees the python-driver name-space & cached data. */
BPY_driver_exit();
/* Clear Python values in the context so freeing the context after Python exits doesn't crash. */
bpy_context_end(BPY_context_get());