This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 3e230cc59b67909940899327e0859b4c96f2bd1e Author: ligd <[email protected]> AuthorDate: Tue Jan 20 17:31:02 2026 +0800 libc/stdio: Fix flockfile/funlockfile usage in puts() and fputws_unlocked(). puts() locks stream, its copy of stdout, but unlocked stdout, which is evaluated again. Unlock stream, so that the unlock always matches the lock. fputws_unlocked() released the stream lock on a write error although it never takes it. fputws() holds the lock around the call and releases it afterwards, so a write error released the lock twice, and an application calling fputws_unlocked() directly released a lock it did not hold. Remove that funlockfile(). Signed-off-by: ligd <[email protected]> Signed-off-by: ganjing <[email protected]> --- libs/libc/stdio/lib_fputws.c | 1 - libs/libc/stdio/lib_puts.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/libs/libc/stdio/lib_fputws.c b/libs/libc/stdio/lib_fputws.c index f15c1d927a9..eb3495ac16b 100644 --- a/libs/libc/stdio/lib_fputws.c +++ b/libs/libc/stdio/lib_fputws.c @@ -66,7 +66,6 @@ int fputws_unlocked(FAR const wchar_t *ws, FAR FILE *f) { if (lib_fwrite_unlocked(buf, l, f) < l) { - funlockfile(f); return -1; } } diff --git a/libs/libc/stdio/lib_puts.c b/libs/libc/stdio/lib_puts.c index 7b751e4f912..c33295b0de8 100644 --- a/libs/libc/stdio/lib_puts.c +++ b/libs/libc/stdio/lib_puts.c @@ -83,7 +83,7 @@ int puts(FAR const IPTR char *s) } } - funlockfile(stdout); + funlockfile(stream); return nput; #else size_t len = strlen(s);
