nuttx/libs/libc/stdio
ligd b544ead842 libc/stdio: Fix flockfile/funlockfile usage bugs
Two critical bugs fixed that could cause deadlock:

1. lib_puts.c: flockfile/funlockfile variable mismatch
   - puts() was locking 'stream' but unlocking 'stdout'
   - Although they usually point to the same object, this inconsistency
     can cause lock count mismatch in edge cases, leading to deadlock
   - Fixed to consistently use 'stream' for both lock and unlock

2. lib_fputws.c: incorrect funlockfile in _unlocked function
   - fputws_unlocked() should not call funlockfile() per its semantics
   - When fputws() calls fputws_unlocked(), the error path would cause
     double unlock (once in fputws_unlocked, once in fputws)
   - Removed the funlockfile() call from fputws_unlocked()

These bugs were identified while debugging a deadlock on port 20819
where Thread 26 held stdout lock and waited for Thread 989, while
Thread 989 was blocked trying to acquire the same lock in puts().

Signed-off-by: ligd <liguiding1@xiaomi.com>
2026-04-21 01:35:47 +08:00
..
CMakeLists.txt libc: Move stream printf/scanf from libc/stdio to libc/stream 2026-04-21 01:24:39 +08:00
Kconfig Discourage the use of LIBC_PRINT_EXTENSION 2026-04-21 01:12:30 +08:00
Make.defs libc: Move stream printf/scanf from libc/stdio to libc/stream 2026-04-21 01:24:39 +08:00
lib_asprintf.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_clearerr.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_dprintf.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_fclose.c fclose: fix fclose() donot fflush the unwritable stream. 2026-04-21 01:33:05 +08:00
lib_feof.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_ferror.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_fflush.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_fgetc.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_fgetpos.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_fgets.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_fgetwc.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_fileno.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_fmemopen.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_fopen.c fopen/freopen: clear pushback buffer for new streams 2026-04-21 01:33:31 +08:00
lib_fopencookie.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_fprintf.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_fputc.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_fputs.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_fputwc.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_fputws.c libc/stdio: Fix flockfile/funlockfile usage bugs 2026-04-21 01:35:47 +08:00
lib_fread.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_freopen.c fopen/freopen: clear pushback buffer for new streams 2026-04-21 01:33:31 +08:00
lib_fscanf.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_fseek.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_fseeko.c fseek: clear EOF indicator in fseek() 2026-04-21 01:31:54 +08:00
lib_fsetpos.c fsetpos: makes the fsetpos function comply with POSIX standard 2026-04-21 01:29:44 +08:00
lib_ftell.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_ftello.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_fwrite.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_getc.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_getchar.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_getdelim.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_gets.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_gets_s.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_getwc.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_libdgets.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_libfflush.c fflush: handle ungetc buffer and file position when fflush a read-only stream. 2026-04-21 01:33:02 +08:00
lib_libfgets.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_libfilelock.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_libflushall.c mutex: add mutex_type.h 2026-04-21 01:31:31 +08:00
lib_libfread_unlocked.c gets/fgets/getc/fread: stop stream reads when EOF indicator is set. 2026-04-21 01:31:52 +08:00
lib_libfwrite.c lib_fwrite_unlocked: support _IOLBF line-buffered flush on newline 2026-04-21 01:32:34 +08:00
lib_libgetstreams.c tls: split tls.h to tls.h and tls_task.h 2026-04-21 01:35:03 +08:00
lib_open_memstream.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_perror.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_printf.c libs/libc: fix compile error. 2026-04-21 01:23:54 +08:00
lib_putc.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_putchar.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_puts.c libc/stdio: Fix flockfile/funlockfile usage bugs 2026-04-21 01:35:47 +08:00
lib_putwc.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_putwchar.c libs/libc: fix compile error. 2026-04-21 01:23:54 +08:00
lib_rdflush_unlocked.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_remove.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_renameat.c rename lib_pathbuffer to lib_tempbuffer 2026-04-21 01:18:29 +08:00
lib_rewind.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_scanf.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_setbuf.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_setbuffer.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_setvbuf.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_snprintf.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_sprintf.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_sscanf.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_tempnam.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_tmpfile.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_tmpnam.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_ungetc.c lib_ungetc.c: fix the ungetc() did not clear the EOF. 2026-04-21 01:31:26 +08:00
lib_ungetwc.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_vasprintf.c mutex: add mutex_type.h 2026-04-21 01:31:31 +08:00
lib_vdprintf.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_vfprintf.c printf: Fix printf() to return negative value when the file descriptor is not open for writing. 2026-04-21 01:31:51 +08:00
lib_vfscanf.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_vprintf.c libs/libc: fix compile error. 2026-04-21 01:23:54 +08:00
lib_vscanf.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_vsnprintf.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_vsprintf.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00
lib_vsscanf.c stream_getc: use lib_stream_eof instead of EOF 2026-04-21 01:14:32 +08:00
lib_wrflush_unlocked.c Merge branch 'master' into vela 2026-04-21 01:12:27 +08:00