Skip to content

Commit

Permalink
Fix segfaults
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
swails committed Jul 21, 2018
1 parent 5fee11e commit ecfdb3c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/_rdparm.cpp
Expand Up @@ -38,11 +38,14 @@ static PyObject* rdparm(PyObject *self, PyObject *args) {
ParmFormatMap parmFormats;
std::vector<std::string> 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";
Expand All @@ -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();
Expand Down

0 comments on commit ecfdb3c

Please sign in to comment.