Skip to content

Commit 979dd2b

Browse files
committed
gh-102494: fix MemoryError when using selectors on Solaris
1 parent 9d3b53c commit 979dd2b

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
@@ -1133,7 +1133,7 @@ newDevPollObject(PyObject *module)
11331133
struct rlimit limit;
11341134

11351135
/*
1136-
** If we try to process more that getrlimit()
1136+
** If we try to process more than getrlimit()
11371137
** fds, the kernel will give an error, so
11381138
** we set the limit here. It is a dynamic
11391139
** value, because we can change rlimit() anytime.
@@ -1144,6 +1144,15 @@ newDevPollObject(PyObject *module)
11441144
return NULL;
11451145
}
11461146

1147+
/*
1148+
** If the limit is too high (or RLIM_INFINITY), we might allocate huge
1149+
** amounts of memory (or even fail to allocate). Because of that, we limit
1150+
** the number of allocated structs to 2^18 (which is ~4MB of memory).
1151+
*/
1152+
if (limit.rlim_cur > (rlim_t)262144) {
1153+
limit.rlim_cur = (rlim_t)262144;
1154+
}
1155+
11471156
fd_devpoll = _Py_open("/dev/poll", O_RDWR);
11481157
if (fd_devpoll == -1)
11491158
return NULL;

0 commit comments

Comments
 (0)