From 4cffa48043915da690cd095b813be0a0d51d1de6 Mon Sep 17 00:00:00 2001 From: dinghong Date: Thu, 24 Jul 2025 10:51:13 +0800 Subject: [PATCH] fix: RandomAccessFile fd Signed-off-by: dinghong --- interfaces/kits/cj/src/file_fs_impl.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/interfaces/kits/cj/src/file_fs_impl.cpp b/interfaces/kits/cj/src/file_fs_impl.cpp index 23b889c87..a9c1432d8 100644 --- a/interfaces/kits/cj/src/file_fs_impl.cpp +++ b/interfaces/kits/cj/src/file_fs_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -390,6 +390,7 @@ std::tuple> FileFsImpl::CreateRandomAccessFi auto fdg = CreateUniquePtr(dupFd, false); if (fdg == nullptr) { HILOGE("Failed to request heap memory."); + close(dupFd); return { GetErrorCode(ENOMEM), nullptr}; } fileInfo = FileInfo { false, nullptr, move(fdg) }; @@ -399,6 +400,7 @@ std::tuple> FileFsImpl::CreateRandomAccessFi ptr->filePointer = 0; auto randomAccessFileImpl = FFIData::Create(std::move(ptr)); if (!randomAccessFileImpl) { + close(dupFd); return {GetErrorCode(ENOMEM), nullptr}; } return {SUCCESS_CODE, randomAccessFileImpl}; -- Gitee