Skip to content

Commit 10cbc94

Browse files
committed
Merge branch 'Python-coverity'
* Python-coverity: Fix possible refleaks. Check Py{Bytes,String}_AsStringAndSize() for failure
2 parents a5d5072 + 58e409d commit 10cbc94

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Lib/python/pyhead.swg

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ SWIG_Python_str_AsChar(PyObject *str)
4343
if (str) {
4444
char *cstr;
4545
Py_ssize_t len;
46-
PyBytes_AsStringAndSize(str, &cstr, &len);
47-
newstr = (char *) malloc(len+1);
48-
memcpy(newstr, cstr, len+1);
46+
if (PyBytes_AsStringAndSize(str, &cstr, &len) != -1) {
47+
newstr = (char *) malloc(len+1);
48+
if (newstr)
49+
memcpy(newstr, cstr, len+1);
50+
}
4951
Py_XDECREF(str);
5052
}
5153
return newstr;

Lib/python/pystrings.swg

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
3232
if (alloc)
3333
*alloc = SWIG_NEWOBJ;
3434
%#endif
35-
PyBytes_AsStringAndSize(obj, &cstr, &len);
35+
if (PyBytes_AsStringAndSize(obj, &cstr, &len) == -1)
36+
return SWIG_TypeError;
3637
%#else
37-
PyString_AsStringAndSize(obj, &cstr, &len);
38+
if (PyString_AsStringAndSize(obj, &cstr, &len) == -1)
39+
return SWIG_TypeError;
3840
%#endif
3941
if (cptr) {
4042
if (alloc) {

0 commit comments

Comments
 (0)