Fix refcount leak in error cases. Bug found by coverity.
This commit is contained in:
parent
847c43a22d
commit
3a6a0431d0
|
@ -1452,11 +1452,14 @@ Z_set(void *ptr, PyObject *value, Py_ssize_t size)
|
||||||
size += 1; /* terminating NUL */
|
size += 1; /* terminating NUL */
|
||||||
size *= sizeof(wchar_t);
|
size *= sizeof(wchar_t);
|
||||||
buffer = (wchar_t *)PyMem_Malloc(size);
|
buffer = (wchar_t *)PyMem_Malloc(size);
|
||||||
if (!buffer)
|
if (!buffer) {
|
||||||
|
Py_DECREF(value);
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
|
}
|
||||||
memset(buffer, 0, size);
|
memset(buffer, 0, size);
|
||||||
keep = PyCObject_FromVoidPtr(buffer, PyMem_Free);
|
keep = PyCObject_FromVoidPtr(buffer, PyMem_Free);
|
||||||
if (!keep) {
|
if (!keep) {
|
||||||
|
Py_DECREF(value);
|
||||||
PyMem_Free(buffer);
|
PyMem_Free(buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue