Fix possible refleaks.

This commit is contained in:
Zackery Spytz 2020-01-29 10:00:22 -07:00
commit 58e409dd2b

View file

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