diff options
author | Antonin Décimo <antonin.decimo@gmail.com> | 2020-06-15 15:46:58 +0200 |
---|---|---|
committer | Tudor Brindus <me@tbrindus.ca> | 2020-07-30 22:02:42 -0400 |
commit | 5c67d997948309d881ed94387309865c76ecddcb (patch) | |
tree | 664a2e35fdd73bac76ed62d758521144c81383a6 /common | |
parent | Fix incorrect format specifiers (diff) | |
download | sway-5c67d997948309d881ed94387309865c76ecddcb.tar.gz sway-5c67d997948309d881ed94387309865c76ecddcb.tar.zst sway-5c67d997948309d881ed94387309865c76ecddcb.zip |
common/loop: check return of realloc
Diffstat (limited to 'common')
-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; |