From e62ed67f2643e9a6a730c9c98ba6f40dbe5248c3 Mon Sep 17 00:00:00 2001 From: l30052632 Date: Mon, 25 Nov 2024 11:23:41 +0800 Subject: [PATCH] copy add close Signed-off-by: l30052632 --- interfaces/kits/js/src/mod_fs/properties/copy.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.cpp b/interfaces/kits/js/src/mod_fs/properties/copy.cpp index 36fae91ed..190c18e10 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy.cpp @@ -97,12 +97,16 @@ static int SendFileCore(std::unique_ptr srcFdg, new (nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; if (sendFileReq == nullptr) { HILOGE("Failed to request heap memory."); + close(srcFd); + close(destFd); return ENOMEM; } int64_t offset = 0; struct stat srcStat{}; if (fstat(srcFdg->GetFD(), &srcStat) < 0) { HILOGE("Failed to get stat of file by fd: %{public}d ,errno = %{public}d", srcFdg->GetFD(), errno); + close(srcFd); + close(destFd); return errno; } int32_t ret = 0; @@ -112,23 +116,33 @@ static int SendFileCore(std::unique_ptr srcFdg, offset, MAX_SIZE, nullptr); if (ret < 0) { HILOGE("Failed to sendfile by errno : %{public}d", errno); + close(srcFd); + close(destFd); return errno; } if (infos != nullptr && infos->taskSignal != nullptr) { if (infos->taskSignal->CheckCancelIfNeed(infos->srcPath)) { + close(srcFd); + close(destFd); return ECANCELED; } } offset += static_cast(ret); size -= static_cast(ret); if (ret == 0) { + close(srcFd); + close(destFd); break; } } if (size != 0) { HILOGE("The execution of the sendfile task was terminated, remaining file size %{public}" PRIu64, size); + close(srcFd); + close(destFd); return EIO; } + close(srcFd); + close(destFd); return ERRNO_NOERR; } -- Gitee