From c2287ba2cff59a50848151833404bce0e3cf0a70 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 10 Mar 2020 17:07:19 +0100 Subject: libio: Robust file descriptor reference counting There was a race conditon in the reference counting of file descriptors during a close() operation. After the call to the close handler, the rtems_libio_free() function cleared the flags to zero. However, at this point in time there may still exist some holders of the file descriptor. With RTEMS_DEBUG enabled this could lead to failed assertions in rtems_libio_iop_drop(). Change the code to use only atomic read-modify-write operations on the rtems_libio_iop::flags. --- cpukit/posix/src/shmopen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cpukit/posix/src/shmopen.c') diff --git a/cpukit/posix/src/shmopen.c b/cpukit/posix/src/shmopen.c index 22b5868bda..054a035f16 100644 --- a/cpukit/posix/src/shmopen.c +++ b/cpukit/posix/src/shmopen.c @@ -286,14 +286,14 @@ int shm_open( const char *name, int oflag, mode_t mode ) iop->pathinfo.mt_entry = &rtems_filesystem_null_mt_entry; rtems_filesystem_location_add_to_mt_entry( &iop->pathinfo ); - flags = LIBIO_FLAGS_CLOSE_ON_EXEC; + flags = LIBIO_FLAGS_OPEN | LIBIO_FLAGS_CLOSE_ON_EXEC; if ( (oflag & O_ACCMODE) == O_RDONLY ) { flags |= LIBIO_FLAGS_READ; } else { flags |= LIBIO_FLAGS_READ_WRITE; } - rtems_libio_iop_flags_initialize( iop, flags ); + rtems_libio_iop_flags_set( iop, flags ); return fd; } -- cgit v1.2.3