Skip to content

Commit 955af30

Browse files
author
carpentry-heartbeat[bot]
committed
Restore CARP_MALLOC NULL checks in kqueue and epoll Poll_wait_
The poll(2) fallback implementation accidentally dropped existing NULL checks from the kqueue and epoll backends. Restores the 3 checks in kqueue (fds, flags, result.data) and 1 in epoll (result.data) that were present on master.
1 parent 8b485ce commit 955af30

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/poll.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,16 @@ Array Poll_wait_(Poll* p, int timeout_ms) {
123123

124124
if (n > 0) {
125125
fds = (int*)CARP_MALLOC(n * sizeof(int));
126+
if (!fds) {
127+
result.len = 0; result.capacity = 0; result.data = NULL;
128+
return result;
129+
}
126130
flags = (int*)CARP_MALLOC(n * sizeof(int));
131+
if (!flags) {
132+
CARP_FREE(fds);
133+
result.len = 0; result.capacity = 0; result.data = NULL;
134+
return result;
135+
}
127136

128137
for (int i = 0; i < n; i++) {
129138
int fd = (int)events[i].ident;
@@ -150,6 +159,12 @@ Array Poll_wait_(Poll* p, int timeout_ms) {
150159
result.len = unique;
151160
result.capacity = unique > 0 ? unique : 1;
152161
result.data = CARP_MALLOC(result.capacity * sizeof(PollEvent));
162+
if (!result.data) {
163+
if (fds) CARP_FREE(fds);
164+
if (flags) CARP_FREE(flags);
165+
result.len = 0; result.capacity = 0;
166+
return result;
167+
}
153168

154169
for (int i = 0; i < unique; i++) {
155170
PollEvent* e = &((PollEvent*)result.data)[i];
@@ -219,6 +234,10 @@ Array Poll_wait_(Poll* p, int timeout_ms) {
219234
result.len = n;
220235
result.capacity = n > 0 ? n : 1;
221236
result.data = CARP_MALLOC(result.capacity * sizeof(PollEvent));
237+
if (!result.data) {
238+
result.len = 0; result.capacity = 0;
239+
return result;
240+
}
222241

223242
for (int i = 0; i < n; i++) {
224243
PollEvent* e = &((PollEvent*)result.data)[i];

0 commit comments

Comments
 (0)