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 <liguiding1@xiaomi.com>
This commit is contained in:
ligd
2025-11-18 16:01:16 +08:00
committed by Donny(董九柱)
parent a8280b0eee
commit 8c95e9e05c
+15
View File
@@ -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);