MT#55283 protect timer_fd with mutex

Solves a race condition when deleting a stream, as the fd might get
closed just as another thread tries to read from it, leading to EBADF
read error.

Change-Id: I8ea3ff72c2788ce3051a86a0bbd1650b03965376
coverity_scan
Richard Fuchs 3 months ago
parent 018de40f2d
commit 64eba103e3

@ -339,7 +339,13 @@ static void readable(int fd, void *o) {
while (true) {
uint64_t exp;
ssize_t ret = read(fd, &exp, sizeof(exp));
ssize_t ret;
{
LOCK(&s->lock);
if (s->timer_fd != fd)
break;
ret = read(fd, &exp, sizeof(exp));
}
if (ret != sizeof(exp)) {
if (ret == -1 && (errno == EAGAIN || errno == EWOULDBLOCK))
break;
@ -584,8 +590,14 @@ static void del_stream(void) {
if (!s)
return;
poller_del_item(rtpe_poller, s->timer_fd);
s->timer_fd = -1;
int fd;
{
LOCK(&s->lock);
fd = s->timer_fd;
s->timer_fd = -1;
}
poller_del_item(rtpe_poller, fd);
obj_put(s);
}

Loading…
Cancel
Save