Fix refcount leak in error cases. Bug found by coverity.

This commit is contained in:
Thomas Heller 2009-01-13 17:32:28 +00:00
parent 847c43a22d
commit 3a6a0431d0
1 changed files with 4 additions and 1 deletions

View File

@ -1452,11 +1452,14 @@ Z_set(void *ptr, PyObject *value, Py_ssize_t size)
size += 1; /* terminating NUL */
size *= sizeof(wchar_t);
buffer = (wchar_t *)PyMem_Malloc(size);
if (!buffer)
if (!buffer) {
Py_DECREF(value);
return PyErr_NoMemory();
}
memset(buffer, 0, size);
keep = PyCObject_FromVoidPtr(buffer, PyMem_Free);
if (!keep) {
Py_DECREF(value);
PyMem_Free(buffer);
return NULL;
}