From ecfdb3c0ecaf409213fef5ac0d16219b6fc8566e Mon Sep 17 00:00:00 2001 From: Jason Swails Date: Sat, 21 Jul 2018 00:59:43 -0400 Subject: [PATCH] Fix segfaults - Py_END_ALLOW_THREADS *must* be called, so it needs to come *before* the error-checking that returns if any exit status is not an error condition. --- src/_rdparm.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/_rdparm.cpp b/src/_rdparm.cpp index aa09d723e..af7659c12 100644 --- a/src/_rdparm.cpp +++ b/src/_rdparm.cpp @@ -38,11 +38,14 @@ static PyObject* rdparm(PyObject *self, PyObject *args) { ParmFormatMap parmFormats; std::vector flagList; std::string version; + ExitStatus retval; Py_BEGIN_ALLOW_THREADS - ExitStatus retval = readparm(fname, flagList, parmData, parmComments, - unkParmData, parmFormats, version); + retval = readparm(fname, flagList, parmData, parmComments, + unkParmData, parmFormats, version); + + Py_END_ALLOW_THREADS if (retval == NOOPEN) { error_message = "Could not open " + fname + " for reading"; @@ -68,8 +71,6 @@ static PyObject* rdparm(PyObject *self, PyObject *args) { return NULL; } - Py_END_ALLOW_THREADS - // If we got here, the parsing must have been OK. Create the parm_data, // formats, and comments dicts to pass back to Python PyObject *parm_data = PyDict_New();