diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.cpp b/interfaces/kits/js/src/mod_fs/properties/copy.cpp index 36fae91ed445ea81db56360e6bca01c215d6f751..190c18e1055b2d34b069811f5cc45657eae17734 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; }