Skip to content

Commit

Permalink
BUG: fixed reference leak when SWIG passing tuples or lists
Browse files Browse the repository at this point in the history
Fixes #2705.  Calls to PySequence_GetItem have been updated in pyBase.i to decrement the reference count correctly.
  • Loading branch information
brad-t-moore committed Aug 31, 2021
1 parent f87c9bd commit 95ee15a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Wrapping/Generators/Python/PyBase/pyBase.i
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,11 @@ str = str
} else if (PyFloat_Check(o)) {
itks[i] = (type)PyFloat_AsDouble(o);
} else {
Py_DECREF(o);
PyErr_SetString(PyExc_ValueError,"Expecting a sequence of int or float");
return NULL;
}
Py_DECREF(o);
}
$1 = &itks;
}else if (PyInt_Check($input)) {
Expand Down Expand Up @@ -649,9 +651,11 @@ str = str
} else if (PyFloat_Check(o)) {
itks[i] = (type)PyFloat_AsDouble(o);
} else {
Py_DECREF(o);
PyErr_SetString(PyExc_ValueError,"Expecting a sequence of int or float");
return NULL;
}
Py_DECREF(o);
}
$1 = itks;
}else if (PyInt_Check($input)) {
Expand Down Expand Up @@ -723,9 +727,11 @@ str = str
} else if (PyFloat_Check(o)) {
itks[i] = (value_type)PyFloat_AsDouble(o);
} else {
Py_DECREF(o);
PyErr_SetString(PyExc_ValueError,"Expecting a sequence of int or float");
return NULL;
}
Py_DECREF(o);
}
$1 = &itks;
}
Expand Down Expand Up @@ -754,9 +760,11 @@ str = str
} else if (PyFloat_Check(o)) {
itks[i] = (value_type)PyFloat_AsDouble(o);
} else {
Py_DECREF(o);
PyErr_SetString(PyExc_ValueError,"Expecting a sequence of int or float");
return NULL;
}
Py_DECREF(o);
}
$1 = itks;
}
Expand Down Expand Up @@ -806,9 +814,11 @@ str = str
if (PyInt_Check(o) || PyLong_Check(o)) {
itks[i] = PyInt_AsLong(o);
} else {
Py_DECREF(o);
PyErr_SetString(PyExc_ValueError,"Expecting a sequence of int (or long)");
return NULL;
}
Py_DECREF(o);
}
$1 = &itks;
}else if (PyInt_Check($input) || PyLong_Check($input)) {
Expand Down Expand Up @@ -845,9 +855,11 @@ str = str
if (PyInt_Check(o) || PyLong_Check(o)) {
itks[i] = PyInt_AsLong(o);
} else {
Py_DECREF(o);
PyErr_SetString(PyExc_ValueError,"Expecting a sequence of int (or long)");
return NULL;
}
Py_DECREF(o);
}
$1 = itks;
}else if (PyInt_Check($input) || PyLong_Check($input)) {
Expand Down Expand Up @@ -932,9 +944,11 @@ str = str
if(SWIG_ConvertPtr(o,(void **)(&raw_ptr),$descriptor(swig_name *), 0) == 0) {
vec_smartptr.push_back(raw_ptr);
} else {
Py_DECREF(o);
PyErr_SetString(PyExc_ValueError,"Expecting a sequence of raw pointers (" #swig_name ")." );
SWIG_fail;
}
Py_DECREF(o);
}
$1 = vec_smartptr;
}
Expand Down

0 comments on commit 95ee15a

Please sign in to comment.