Skip to content

Commit 4cfa774

Browse files
committed
gh-102494: fix MemoryError when using selectors on Solaris
1 parent d8485d6 commit 4cfa774

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

Modules/selectmodule.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ newDevPollObject(PyObject *module)
10951095
struct rlimit limit;
10961096

10971097
/*
1098-
** If we try to process more that getrlimit()
1098+
** If we try to process more than getrlimit()
10991099
** fds, the kernel will give an error, so
11001100
** we set the limit here. It is a dynamic
11011101
** value, because we can change rlimit() anytime.
@@ -1106,6 +1106,15 @@ newDevPollObject(PyObject *module)
11061106
return NULL;
11071107
}
11081108

1109+
/*
1110+
** If the limit is too high (or RLIM_INFINITY), we might allocate huge
1111+
** amounts of memory (or even fail to allocate). Because of that, we limit
1112+
** the number of allocated structs to 2^18 (which is ~4MB of memory).
1113+
*/
1114+
if (limit.rlim_cur > (rlim_t)262144) {
1115+
limit.rlim_cur = (rlim_t)262144;
1116+
}
1117+
11091118
fd_devpoll = _Py_open("/dev/poll", O_RDWR);
11101119
if (fd_devpoll == -1)
11111120
return NULL;

0 commit comments

Comments
 (0)