mirror of
https://github.com/swaywm/sway.git
synced 2024-11-29 03:11:27 +00:00
common/loop: check return of realloc
This commit is contained in:
parent
bbf7b92fe4
commit
5c67d99794
|
@ -117,9 +117,15 @@ void loop_add_fd(struct loop *loop, int fd, short mask,
|
||||||
struct pollfd pfd = {fd, mask, 0};
|
struct pollfd pfd = {fd, mask, 0};
|
||||||
|
|
||||||
if (loop->fd_length == loop->fd_capacity) {
|
if (loop->fd_length == loop->fd_capacity) {
|
||||||
loop->fd_capacity += 10;
|
int capacity = loop->fd_capacity + 10;
|
||||||
loop->fds = realloc(loop->fds,
|
struct pollfd *tmp = realloc(loop->fds,
|
||||||
sizeof(struct pollfd) * loop->fd_capacity);
|
sizeof(struct pollfd) * capacity);
|
||||||
|
if (!tmp) {
|
||||||
|
sway_log(SWAY_ERROR, "Unable to allocate memory for pollfd");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
loop->fds = tmp;
|
||||||
|
loop->fd_capacity = capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
loop->fds[loop->fd_length++] = pfd;
|
loop->fds[loop->fd_length++] = pfd;
|
||||||
|
|
Loading…
Reference in a new issue