From: Thomas Heller Date: Tue, 13 Jan 2009 17:32:28 +0000 (+0000) Subject: Fix refcount leak in error cases. Bug found by coverity. X-Git-Tag: v2.7a1~2301 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a6a0431d0a016119b3246748b5aa245ff1ac4fe;p=thirdparty%2FPython%2Fcpython.git Fix refcount leak in error cases. Bug found by coverity. --- diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index ef85b87cbf28..96264e7e9a15 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; }