This is an automated email from the ASF dual-hosted git repository. jiuzhudong pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 8c95e9e05c33a6855071956806b00cc92a9b86e3 Author: ligd <[email protected]> AuthorDate: Tue Nov 18 16:01:16 2025 +0800 freopen: fix fdsan report error [<0x60ddce>] __assert+0x1d/0x5c [<0x60f2be>] android_fdsan_exchange_owner_tag+0x71/0xc0 [<0x60a14e>] close+0x19/0x64 [<0xb77b1c>] freopen+0x47/0xd8 [<0x86fe54>] test_nuttx_fs_stream01+0x4f/0x1a4 [<0xcef54e>] cmocka_run_one_test_or_fixture+0xe5/0x3cc [<0xcefd26>] _cmocka_run_group_tests+0x41d/0xbd8 [<0x86cff2>] cmocka_fs_test_main+0x35/0x58 [<0x6a9d1a>] nxtask_startup+0x15/0x30 [<0x641e92>] nxtask_start+0x75/0x94 Signed-off-by: ligd <[email protected]> --- libs/libc/stdio/lib_freopen.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libs/libc/stdio/lib_freopen.c b/libs/libc/stdio/lib_freopen.c index 9cc9f31b514..8489b9b6fb2 100644 --- a/libs/libc/stdio/lib_freopen.c +++ b/libs/libc/stdio/lib_freopen.c @@ -31,6 +31,10 @@ #include <errno.h> #include <unistd.h> +#ifdef CONFIG_FDSAN +# include <android/fdsan.h> +#endif + #include "libc.h" /**************************************************************************** @@ -113,11 +117,22 @@ FAR FILE *freopen(FAR const char *path, FAR const char *mode, /* close the old fd */ +#ifdef CONFIG_FDSAN + android_fdsan_close_with_tag(fileno(stream), + android_fdsan_create_owner_tag(ANDROID_FDSAN_OWNER_TYPE_FILE, + (uintptr_t)stream)); +#else close(fileno(stream)); +#endif /* Open the new file and reused the fd */ fd = open(path, oflags, 0666); +#ifdef CONFIG_FDSAN + android_fdsan_exchange_owner_tag(fd, 0, + android_fdsan_create_owner_tag(ANDROID_FDSAN_OWNER_TYPE_FILE, + (uintptr_t)stream)); +#endif flockfile(stream); stream->fs_cookie = (FAR void *)(intptr_t)fd; funlockfile(stream);
