mirror of
https://github.com/NLnetLabs/unbound.git
synced 2024-09-21 14:47:09 +00:00
eliminate unnecessary Python reloading which causes memory leaks
This commit is contained in:
parent
90d42148de
commit
cfd3bcb21e
@ -252,6 +252,16 @@ cleanup:
|
|||||||
Py_XDECREF(exc_tb);
|
Py_XDECREF(exc_tb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* we only want to unwind Python once at exit */
|
||||||
|
void pythonmod_atexit(void)
|
||||||
|
{
|
||||||
|
assert(py_mod_count == 0);
|
||||||
|
assert(maimthr != NULL);
|
||||||
|
|
||||||
|
PyEval_RestoreThread(mainthr);
|
||||||
|
Py_Finalize();
|
||||||
|
}
|
||||||
|
|
||||||
int pythonmod_init(struct module_env* env, int id)
|
int pythonmod_init(struct module_env* env, int id)
|
||||||
{
|
{
|
||||||
int py_mod_idx = py_mod_count++;
|
int py_mod_idx = py_mod_count++;
|
||||||
@ -310,6 +320,9 @@ int pythonmod_init(struct module_env* env, int id)
|
|||||||
#endif
|
#endif
|
||||||
SWIG_init();
|
SWIG_init();
|
||||||
mainthr = PyEval_SaveThread();
|
mainthr = PyEval_SaveThread();
|
||||||
|
|
||||||
|
/* XXX: register callback to unwind Python at exit */
|
||||||
|
atexit(pythonmod_atexit);
|
||||||
}
|
}
|
||||||
|
|
||||||
gil = PyGILState_Ensure();
|
gil = PyGILState_Ensure();
|
||||||
@ -547,11 +560,7 @@ void pythonmod_deinit(struct module_env* env, int id)
|
|||||||
Py_XDECREF(pe->data);
|
Py_XDECREF(pe->data);
|
||||||
PyGILState_Release(gil);
|
PyGILState_Release(gil);
|
||||||
|
|
||||||
if(--py_mod_count==0) {
|
py_mod_count--;
|
||||||
PyEval_RestoreThread(mainthr);
|
|
||||||
Py_Finalize();
|
|
||||||
mainthr = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pe->fname = NULL;
|
pe->fname = NULL;
|
||||||
free(pe);
|
free(pe);
|
||||||
|
Loading…
Reference in New Issue
Block a user