diff options
-rw-r--r-- | common/loop.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/common/loop.c b/common/loop.c index aecad2f3..80fe18ea 100644 --- a/common/loop.c +++ b/common/loop.c | |||
@@ -117,9 +117,15 @@ void loop_add_fd(struct loop *loop, int fd, short mask, | |||
117 | struct pollfd pfd = {fd, mask, 0}; | 117 | struct pollfd pfd = {fd, mask, 0}; |
118 | 118 | ||
119 | if (loop->fd_length == loop->fd_capacity) { | 119 | if (loop->fd_length == loop->fd_capacity) { |
120 | loop->fd_capacity += 10; | 120 | int capacity = loop->fd_capacity + 10; |
121 | loop->fds = realloc(loop->fds, | 121 | struct pollfd *tmp = realloc(loop->fds, |
122 | sizeof(struct pollfd) * loop->fd_capacity); | 122 | sizeof(struct pollfd) * capacity); |
123 | if (!tmp) { | ||
124 | sway_log(SWAY_ERROR, "Unable to allocate memory for pollfd"); | ||
125 | return; | ||
126 | } | ||
127 | loop->fds = tmp; | ||
128 | loop->fd_capacity = capacity; | ||
123 | } | 129 | } |
124 | 130 | ||
125 | loop->fds[loop->fd_length++] = pfd; | 131 | loop->fds[loop->fd_length++] = pfd; |