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/libcsupport/src/fcntl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cpukit/libcsupport/src/fcntl.c') diff --git a/cpukit/libcsupport/src/fcntl.c b/cpukit/libcsupport/src/fcntl.c index ddbf5538f9..86b757e511 100644 --- a/cpukit/libcsupport/src/fcntl.c +++ b/cpukit/libcsupport/src/fcntl.c @@ -45,9 +45,9 @@ static int duplicate_iop( rtems_libio_t *iop ) */ rv = (*diop->pathinfo.handlers->open_h)( diop, NULL, oflag, 0 ); if ( rv == 0 ) { - rtems_libio_iop_flags_initialize( + rtems_libio_iop_flags_set( diop, - rtems_libio_fcntl_flags( oflag ) + LIBIO_FLAGS_OPEN | rtems_libio_fcntl_flags( oflag ) ); rv = rtems_libio_iop_to_descriptor( diop ); } else { -- cgit v1.2.3