cpukit/libio: Fix race condition in iop free

Closes #5490
This commit is contained in:
Aaron Nyholm
2026-02-06 15:57:33 +11:00
committed by Kinsey Moore
parent a0a80f08ca
commit f6933b9c6f

View File

@@ -156,10 +156,15 @@ void rtems_libio_free_iop(
)
{
size_t zero;
unsigned int flags;
/*
* Use atomic test and set so the contents of the if statement
* can only be run once. Therefore only added to the free list once.
*/
flags = rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_FREE );
if ( ( flags & LIBIO_FLAGS_FREE ) == 0 ) {
rtems_libio_lock();
if ( !rtems_libio_iop_is_free( iop ) ) {
/*
* Clear the flags. All references should have been dropped.
*/
@@ -176,9 +181,8 @@ void rtems_libio_free_iop(
*/
*rtems_libio_iop_free_tail = iop;
rtems_libio_iop_free_tail = &iop->data1;
}
rtems_libio_unlock();
}
}
int rtems_libio_count_open_iops(