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
(cherry picked from commit 64eba103e3)
(cherry picked from commit da6ff09842)
mr13.2.1
Richard Fuchs 2 months ago
parent 0daa5fbd7a
commit 629b0db13f

@ -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