aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorAntonin Décimo <antonin.decimo@gmail.com>2020-06-15 15:46:58 +0200
committerTudor Brindus <me@tbrindus.ca>2020-07-30 22:02:42 -0400
commit5c67d997948309d881ed94387309865c76ecddcb (patch)
tree664a2e35fdd73bac76ed62d758521144c81383a6 /common
parentbbf7b92fe4b34288dbe7c58827a1f69428ffb263 (diff)
common/loop: check return of realloc
Diffstat (limited to 'common')
-rw-r--r--common/loop.c12
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,
struct pollfd pfd = {fd, mask, 0};
if (loop->fd_length == loop->fd_capacity) {
- loop->fd_capacity += 10;
- loop->fds = realloc(loop->fds,
- sizeof(struct pollfd) * loop->fd_capacity);
+ int capacity = loop->fd_capacity + 10;
+ struct pollfd *tmp = realloc(loop->fds,
+ 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;