From ca59e81e29df384406f22e4dac969d2080492a08 Mon Sep 17 00:00:00 2001 From: yangbiao59 Date: Wed, 6 Aug 2025 03:20:48 +0000 Subject: [PATCH] =?UTF-8?q?dup=E6=8E=A5=E5=8F=A3=20=E9=87=8A=E6=94=BEdstFd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangbiao59 --- interfaces/kits/js/src/mod_fs/properties/dup.cpp | 2 ++ interfaces/kits/js/src/mod_fs/properties/dup_core.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/interfaces/kits/js/src/mod_fs/properties/dup.cpp b/interfaces/kits/js/src/mod_fs/properties/dup.cpp index 77d71f738..de2de57d3 100644 --- a/interfaces/kits/js/src/mod_fs/properties/dup.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/dup.cpp @@ -51,6 +51,7 @@ napi_value Dup::Sync(napi_env env, napi_callback_info info) new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (!readlink_req) { HILOGE("Failed to request heap memory."); + close(dstFd); NError(ENOMEM).ThrowErr(env); return nullptr; } @@ -58,6 +59,7 @@ napi_value Dup::Sync(napi_env env, napi_callback_info info) int ret = uv_fs_readlink(nullptr, readlink_req.get(), path.c_str(), nullptr); if (ret < 0) { HILOGE("Failed to readlink fd, ret: %{public}d", ret); + close(dstFd); NError(ret).ThrowErr(env); return nullptr; } diff --git a/interfaces/kits/js/src/mod_fs/properties/dup_core.cpp b/interfaces/kits/js/src/mod_fs/properties/dup_core.cpp index 716205149..17d099d13 100644 --- a/interfaces/kits/js/src/mod_fs/properties/dup_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/dup_core.cpp @@ -52,12 +52,14 @@ FsResult DupCore::DoDup(const int32_t &fd) new (std::nothrow) uv_fs_t, FsUtils::FsReqCleanup }; if (!readLinkReq) { HILOGE("Failed to request heap memory."); + close(dstFd); return FsResult::Error(ENOMEM); } string path = "/proc/self/fd/" + to_string(dstFd); int ret = uv_fs_readlink(nullptr, readLinkReq.get(), path.c_str(), nullptr); if (ret < 0) { HILOGE("Failed to readlink fd, ret: %{public}d", ret); + close(dstFd); return FsResult::Error(ret); } return FileInstantiator::InstantiateFile(dstFd, string(static_cast(readLinkReq->ptr)), false); -- Gitee