Commit f69fa175 authored by Thomas Heller's avatar Thomas Heller

Merged revisions 55025 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk/Modules/_ctypes

........
  r55025 | thomas.heller | 2007-04-30 17:44:17 +0200 (Mo, 30 Apr 2007) | 4 lines

  Make sure to call PyErr_NoMemory() in several places where
  PyMem_Malloc() could potentially fail.

  Will backport to the release25-maint branch.
........
parent 80a42c07
...@@ -539,8 +539,10 @@ static int ConvParam(PyObject *obj, int index, struct argument *pa) ...@@ -539,8 +539,10 @@ static int ConvParam(PyObject *obj, int index, struct argument *pa)
size += 1; /* terminating NUL */ size += 1; /* terminating NUL */
size *= sizeof(wchar_t); size *= sizeof(wchar_t);
pa->value.p = PyMem_Malloc(size); pa->value.p = PyMem_Malloc(size);
if (!pa->value.p) if (!pa->value.p) {
PyErr_NoMemory();
return -1; return -1;
}
memset(pa->value.p, 0, size); memset(pa->value.p, 0, size);
pa->keep = PyCObject_FromVoidPtr(pa->value.p, PyMem_Free); pa->keep = PyCObject_FromVoidPtr(pa->value.p, PyMem_Free);
if (!pa->keep) { if (!pa->keep) {
......
...@@ -1389,7 +1389,7 @@ Z_set(void *ptr, PyObject *value, unsigned size) ...@@ -1389,7 +1389,7 @@ Z_set(void *ptr, PyObject *value, unsigned size)
size *= sizeof(wchar_t); size *= sizeof(wchar_t);
buffer = (wchar_t *)PyMem_Malloc(size); buffer = (wchar_t *)PyMem_Malloc(size);
if (!buffer) if (!buffer)
return NULL; 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) {
......
...@@ -72,8 +72,10 @@ StgDict_clone(StgDictObject *dst, StgDictObject *src) ...@@ -72,8 +72,10 @@ StgDict_clone(StgDictObject *dst, StgDictObject *src)
return 0; return 0;
size = sizeof(ffi_type *) * (src->length + 1); size = sizeof(ffi_type *) * (src->length + 1);
dst->ffi_type_pointer.elements = PyMem_Malloc(size); 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; return -1;
}
memcpy(dst->ffi_type_pointer.elements, memcpy(dst->ffi_type_pointer.elements,
src->ffi_type_pointer.elements, src->ffi_type_pointer.elements,
size); size);
...@@ -359,6 +361,10 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct) ...@@ -359,6 +361,10 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
total_align = align ? align : 1; total_align = align ? align : 1;
stgdict->ffi_type_pointer.type = FFI_TYPE_STRUCT; stgdict->ffi_type_pointer.type = FFI_TYPE_STRUCT;
stgdict->ffi_type_pointer.elements = PyMem_Malloc(sizeof(ffi_type *) * (basedict->length + len + 1)); 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, memset(stgdict->ffi_type_pointer.elements, 0,
sizeof(ffi_type *) * (basedict->length + len + 1)); sizeof(ffi_type *) * (basedict->length + len + 1));
memcpy(stgdict->ffi_type_pointer.elements, memcpy(stgdict->ffi_type_pointer.elements,
...@@ -373,6 +379,10 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct) ...@@ -373,6 +379,10 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
total_align = 1; total_align = 1;
stgdict->ffi_type_pointer.type = FFI_TYPE_STRUCT; stgdict->ffi_type_pointer.type = FFI_TYPE_STRUCT;
stgdict->ffi_type_pointer.elements = PyMem_Malloc(sizeof(ffi_type *) * (len + 1)); 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, memset(stgdict->ffi_type_pointer.elements, 0,
sizeof(ffi_type *) * (len + 1)); sizeof(ffi_type *) * (len + 1));
ffi_ofs = 0; ffi_ofs = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment