diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2006-07-23 07:55:55 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2006-07-23 07:55:55 (GMT) |
commit | 93f2ca1f85a80deeb4990540b54ca693843e2e22 (patch) | |
tree | 0e8aff1ae73f78d093618097359277a83e9b6165 /Modules | |
parent | c09efa844419b801ba9d9db9e04ccfb2af59d7f3 (diff) | |
download | cpython-93f2ca1f85a80deeb4990540b54ca693843e2e22.zip cpython-93f2ca1f85a80deeb4990540b54ca693843e2e22.tar.gz cpython-93f2ca1f85a80deeb4990540b54ca693843e2e22.tar.bz2 |
Check the allocation of b_objects and return if there was a failure.
Also fix a few memory leaks in other failure scenarios.
It seems that if b_objects == Py_None, we will have an extra ref to
b_objects. Add XXX comment so hopefully someone documents why the
else isn't necessary or adds it in.
Reported by Klocwork #20
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_ctypes/_ctypes.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index a56663c..18c2db4 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -4521,18 +4521,27 @@ cast(void *ptr, PyObject *src, PyObject *ctype) if (obj->b_objects == Py_None) { Py_DECREF(Py_None); obj->b_objects = PyDict_New(); + if (!obj->b_objects) { + Py_DECREF(result); + return NULL; + } } + /* XXX(nnorwitz): shouldn't the INCREF only be done in an else? */ Py_INCREF(obj->b_objects); result->b_objects = obj->b_objects; if (result->b_objects) { PyObject *index = PyLong_FromVoidPtr((void *)src); int rc; - if (index == NULL) + if (index == NULL) { + Py_DECREF(result); return NULL; + } rc = PyDict_SetItem(result->b_objects, index, src); Py_DECREF(index); - if (rc == -1) + if (rc == -1) { + Py_DECREF(result); return NULL; + } } } /* Should we assert that result is a pointer type? */ |