Skip to content
Snippets Groups Projects
Commit 157ac4fb authored by Gregory Nutt's avatar Gregory Nutt
Browse files

vfs: poll: fix resource leak and memory corruption. From Jussi Kivilinna.

parent e9032594
No related branches found
No related tags found
No related merge requests found
......@@ -162,6 +162,7 @@ static int poll_fdsetup(int fd, FAR struct pollfd *fds, bool setup)
static inline int poll_setup(FAR struct pollfd *fds, nfds_t nfds, sem_t *sem)
{
unsigned int i;
unsigned int j;
int ret;
/* Process each descriptor in the list */
......@@ -190,6 +191,17 @@ static inline int poll_setup(FAR struct pollfd *fds, nfds_t nfds, sem_t *sem)
ret = poll_fdsetup(fds[i].fd, &fds[i], true);
if (ret < 0)
{
/* Setup failed for fds[i]. We now need to teardown previously
* setup fds[0 .. (i - 1)] to release allocated resources and
* to prevent memory corruption by access to freed/released 'fds'
* and 'sem'.
*/
for (j = 0; j < i; j++)
{
(void)poll_fdsetup(fds[j].fd, &fds[j], false);
}
return ret;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment