From b35408733853f16d5806797e64c97ad87607041e Mon Sep 17 00:00:00 2001 From: Loris Nardo Date: Thu, 25 Jul 2024 18:49:37 +0200 Subject: [PATCH] getdents: hold the IOP while performing the operation As all the other functions about file descriptor, getdents should hold the IOP of the file descriptor it is working on. Closes #5074 --- cpukit/libcsupport/src/getdents.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cpukit/libcsupport/src/getdents.c b/cpukit/libcsupport/src/getdents.c index 23b48f669c..b04d26282c 100644 --- a/cpukit/libcsupport/src/getdents.c +++ b/cpukit/libcsupport/src/getdents.c @@ -67,22 +67,27 @@ int getdents( { rtems_libio_t *iop; mode_t type; + int result; /* * Get the file control block structure associated with the file descriptor */ - iop = rtems_libio_iop( dd_fd ); + LIBIO_GET_IOP_WITH_ACCESS( dd_fd, iop, LIBIO_FLAGS_READ, EBADF ); /* * Make sure we are working on a directory */ type = rtems_filesystem_location_type( &iop->pathinfo ); - if ( !S_ISDIR( type ) ) + if ( !S_ISDIR( type ) ) { + rtems_libio_iop_drop( iop ); rtems_set_errno_and_return_minus_one( ENOTDIR ); + } /* * Return the number of bytes that were actually transfered as a result * of the read attempt. */ - return (*iop->pathinfo.handlers->read_h)( iop, dd_buf, dd_len ); + result = (*iop->pathinfo.handlers->read_h)( iop, dd_buf, dd_len ); + rtems_libio_iop_drop( iop ); + return result; }