diff Modules/selectmodule.c @ 48090:2da42dcbb8ce 2.5

Backport code from r65182: Issue #2620: Overflow checking when allocating or reallocating memory was not always being done properly in some python types and extension modules. PyMem_MALLOC, PyMem_REALLOC, PyMem_NEW and PyMem_RESIZE have all been updated to perform better checks and places in the code that would previously leak memory on the error path when such an allocation failed have been fixed.
author Neal Norwitz <nnorwitz@gmail.com>
date Mon, 28 Jul 2008 05:06:20 +0000
parents c67b23397f30
children 787b969d37f0
line wrap: on
line diff
--- a/Modules/selectmodule.c	Fri Jul 25 19:00:48 2008 +0000
+++ b/Modules/selectmodule.c	Mon Jul 28 05:06:20 2008 +0000
@@ -349,10 +349,12 @@
 {
 	Py_ssize_t i, pos;
 	PyObject *key, *value;
+        struct pollfd *old_ufds = self->ufds;
 
 	self->ufd_len = PyDict_Size(self->dict);
-	PyMem_Resize(self->ufds, struct pollfd, self->ufd_len);
+	PyMem_RESIZE(self->ufds, struct pollfd, self->ufd_len);
 	if (self->ufds == NULL) {
+                self->ufds = old_ufds;
 		PyErr_NoMemory();
 		return 0;
 	}