Skip to content

Commit

Permalink
main: Flush list of deleted fhs on fd_poll errors. (#1081)
Browse files Browse the repository at this point in the history
This makes sure deleted fhs structs are not left allocated on
fd_poll errors.
  • Loading branch information
Lastique authored Mar 12, 2024
1 parent c2a2377 commit 3d051cd
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ static int fd_poll(struct re *re)
const uint64_t to = tmr_next_timeout(re->tmrl);
int i, n;
int nfds = re->nfds;
int err = 0;
struct re_fhs *fhs = NULL;
#ifdef HAVE_SELECT
fd_set rfds, wfds, efds;
Expand Down Expand Up @@ -827,11 +828,14 @@ static int fd_poll(struct re *re)
default:
(void)to;
DEBUG_WARNING("no polling method set\n");
return EINVAL;
err = EINVAL;
goto out;
}

if (n < 0)
return RE_ERRNO_SOCK;
if (n < 0) {
err = RE_ERRNO_SOCK;
goto out;
}

/* Check for events */
for (i=0; (n > 0) && (i < nfds); i++) {
Expand Down Expand Up @@ -908,7 +912,8 @@ static int fd_poll(struct re *re)
#endif

default:
return EINVAL;
err = EINVAL;
goto out;
}

if (!flags)
Expand All @@ -926,10 +931,11 @@ static int fd_poll(struct re *re)
--n;
}

out:
/* Delayed fhs deref to avoid dangling fhs pointers */
fhsld_flush(re);

return 0;
return err;
}


Expand Down

0 comments on commit 3d051cd

Please sign in to comment.