File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments