Merge branch 'Python-coverity'

* Python-coverity:
  Fix possible refleaks.
  Check Py{Bytes,String}_AsStringAndSize() for failure
This commit is contained in:
William S Fulton 2020-01-31 19:14:47 +00:00
commit 10cbc9481f
2 changed files with 9 additions and 5 deletions

View file

@ -43,9 +43,11 @@ SWIG_Python_str_AsChar(PyObject *str)
if (str) {
char *cstr;
Py_ssize_t len;
PyBytes_AsStringAndSize(str, &cstr, &len);
newstr = (char *) malloc(len+1);
memcpy(newstr, cstr, len+1);
if (PyBytes_AsStringAndSize(str, &cstr, &len) != -1) {
newstr = (char *) malloc(len+1);
if (newstr)
memcpy(newstr, cstr, len+1);
}
Py_XDECREF(str);
}
return newstr;

View file

@ -32,9 +32,11 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
if (alloc)
*alloc = SWIG_NEWOBJ;
%#endif
PyBytes_AsStringAndSize(obj, &cstr, &len);
if (PyBytes_AsStringAndSize(obj, &cstr, &len) == -1)
return SWIG_TypeError;
%#else
PyString_AsStringAndSize(obj, &cstr, &len);
if (PyString_AsStringAndSize(obj, &cstr, &len) == -1)
return SWIG_TypeError;
%#endif
if (cptr) {
if (alloc) {