From 3a6a0431d0a016119b3246748b5aa245ff1ac4fe Mon Sep 17 00:00:00 2001 From: Thomas Heller Date: Tue, 13 Jan 2009 17:32:28 +0000 Subject: Fix refcount leak in error cases. Bug found by coverity. --- Modules/_ctypes/cfield.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index ef85b87..96264e7 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -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; } -- cgit v0.12