Fix ancient python GIL locking bug on callback (RhBug:1632488)

Introduced in commit c7881d8017 back in 2002,
synthesizing a python object for the callback occurs before retaking
the GIL lock, which is not allowed. Somehow this has managed to stay
latent all these years, and even now requires fairly specific conditions:
when the callback gets called without an associated key, such as erasures
or file trigger script start/stop events (in the case of RhBug:1632488),
when Python 3 is running in PYTHONMALLOC=debug mode,
it crashes with "Python memory allocator called without holding the GIL".

Simply retake the lock before any Python operations take place to fix.
This commit is contained in:
Panu Matilainen 2018-10-03 11:51:38 +03:00
parent d5b66a81b1
commit 531dc8495c
1 changed files with 2 additions and 2 deletions

View File

@ -495,6 +495,8 @@ rpmtsCallback(const void * hd, const rpmCallbackType what,
if (cbInfo->cb == Py_None) return NULL;
PyEval_RestoreThread(cbInfo->_save);
/* Synthesize a python object for callback (if necessary). */
if (pkgObj == NULL) {
if (h) {
@ -506,8 +508,6 @@ rpmtsCallback(const void * hd, const rpmCallbackType what,
} else
Py_INCREF(pkgObj);
PyEval_RestoreThread(cbInfo->_save);
args = Py_BuildValue("(iLLOO)", what, amount, total, pkgObj, cbInfo->data);
result = PyEval_CallObject(cbInfo->cb, args);
Py_DECREF(args);