diff options
author | Thomas Heller <theller@ctypes.org> | 2007-04-30 15:44:17 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2007-04-30 15:44:17 (GMT) |
commit | 5a901bd3cc396b17645d0d4012faf63db9e3ab42 (patch) | |
tree | 3ecb0415c2fbdfebdb002614109498c32d0a77d8 | |
parent | 7a0da19087bfd5e01bcada885b4d0786749b99cf (diff) | |
download | cpython-5a901bd3cc396b17645d0d4012faf63db9e3ab42.zip cpython-5a901bd3cc396b17645d0d4012faf63db9e3ab42.tar.gz cpython-5a901bd3cc396b17645d0d4012faf63db9e3ab42.tar.bz2 |
Make sure to call PyErr_NoMemory() in several places where
PyMem_Malloc() could potentially fail.
Will backport to the release25-maint branch.
-rw-r--r-- | Modules/_ctypes/callproc.c | 4 | ||||
-rw-r--r-- | Modules/_ctypes/cfield.c | 2 | ||||
-rw-r--r-- | Modules/_ctypes/stgdict.c | 12 |
3 files changed, 15 insertions, 3 deletions
diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index 074573a..b7dda48 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -539,8 +539,10 @@ static int ConvParam(PyObject *obj, int index, struct argument *pa) size += 1; /* terminating NUL */ size *= sizeof(wchar_t); pa->value.p = PyMem_Malloc(size); - if (!pa->value.p) + if (!pa->value.p) { + PyErr_NoMemory(); return -1; + } memset(pa->value.p, 0, size); pa->keep = PyCObject_FromVoidPtr(pa->value.p, PyMem_Free); if (!pa->keep) { diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index 9b90882..e7bf274 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -1426,7 +1426,7 @@ Z_set(void *ptr, PyObject *value, unsigned size) size *= sizeof(wchar_t); buffer = (wchar_t *)PyMem_Malloc(size); if (!buffer) - return NULL; + return PyErr_NoMemory(); memset(buffer, 0, size); keep = PyCObject_FromVoidPtr(buffer, PyMem_Free); if (!keep) { diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c index 8fd9a1e..5651d62 100644 --- a/Modules/_ctypes/stgdict.c +++ b/Modules/_ctypes/stgdict.c @@ -72,8 +72,10 @@ StgDict_clone(StgDictObject *dst, StgDictObject *src) return 0; size = sizeof(ffi_type *) * (src->length + 1); dst->ffi_type_pointer.elements = PyMem_Malloc(size); - if (dst->ffi_type_pointer.elements == NULL) + if (dst->ffi_type_pointer.elements == NULL) { + PyErr_NoMemory(); return -1; + } memcpy(dst->ffi_type_pointer.elements, src->ffi_type_pointer.elements, size); @@ -359,6 +361,10 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct) total_align = align ? align : 1; stgdict->ffi_type_pointer.type = FFI_TYPE_STRUCT; stgdict->ffi_type_pointer.elements = PyMem_Malloc(sizeof(ffi_type *) * (basedict->length + len + 1)); + if (stgdict->ffi_type_pointer.elements == NULL) { + PyErr_NoMemory(); + return -1; + } memset(stgdict->ffi_type_pointer.elements, 0, sizeof(ffi_type *) * (basedict->length + len + 1)); memcpy(stgdict->ffi_type_pointer.elements, @@ -373,6 +379,10 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct) total_align = 1; stgdict->ffi_type_pointer.type = FFI_TYPE_STRUCT; stgdict->ffi_type_pointer.elements = PyMem_Malloc(sizeof(ffi_type *) * (len + 1)); + if (stgdict->ffi_type_pointer.elements == NULL) { + PyErr_NoMemory(); + return -1; + } memset(stgdict->ffi_type_pointer.elements, 0, sizeof(ffi_type *) * (len + 1)); ffi_ofs = 0; |