aboutsummaryrefslogtreecommitdiffhomepage
path: root/input
diff options
context:
space:
mode:
authorGravatar shdown <shdownnine@gmail.com>2014-08-30 14:08:13 +0400
committerGravatar wm4 <wm4@nowhere>2014-08-30 15:15:37 +0200
commit8ee1bcf1fac5f05629d4aa5b165e2922bdda6d49 (patch)
treed5c4b758ce1b920d7c9dd5b7a5d9a98d224a9a1f /input
parente2ecf3d03d5e5667fe7c28bee3c14c67eb447a5c (diff)
input: handle reaching MP_MAX_FDS correctly
Don't dereference fd and increment ictx->num_fds on fail.
Diffstat (limited to 'input')
-rw-r--r--input/input.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/input/input.c b/input/input.c
index 908d50d014..db6e26aab5 100644
--- a/input/input.c
+++ b/input/input.c
@@ -858,17 +858,17 @@ int mp_input_add_fd(struct input_ctx *ictx, int unix_fd, int select,
MP_ERR(ictx, "Too many file descriptors.\n");
} else {
fd = &ictx->fds[ictx->num_fds];
+ *fd = (struct input_fd){
+ .log = ictx->log,
+ .fd = unix_fd,
+ .select = select,
+ .read_cmd = read_cmd_func,
+ .read_key = read_key_func,
+ .close_func = close_func,
+ .ctx = ctx,
+ };
+ ictx->num_fds++;
}
- *fd = (struct input_fd){
- .log = ictx->log,
- .fd = unix_fd,
- .select = select,
- .read_cmd = read_cmd_func,
- .read_key = read_key_func,
- .close_func = close_func,
- .ctx = ctx,
- };
- ictx->num_fds++;
input_unlock(ictx);
return !!fd;
}