From 91914143980eca085af0622e235464b95509e478 Mon Sep 17 00:00:00 2001 From: wcj Date: Mon, 18 Aug 2025 17:22:06 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1.2=20new=20=E5=88=86=E9=85=8D=E5=86=85?= =?UTF-8?q?=E5=AD=98=E6=97=B6=E5=BC=82=E5=B8=B8=E5=9C=BA=E6=99=AF=E5=A4=84?= =?UTF-8?q?=E7=90=86=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuchengjun Change-Id: Ic085b549ab7feee096560c6e80a0467bbb6daa9d --- .../js/src/mod_fs/class_atomicfile/fs_atomicfile.cpp | 6 +++++- interfaces/kits/js/src/mod_fs/class_file/fs_file.cpp | 2 +- .../class_randomaccessfile/fs_randomaccessfile.cpp | 4 ++-- .../mod_fs/class_readeriterator/fs_reader_iterator.cpp | 2 +- interfaces/kits/js/src/mod_fs/class_stat/fs_stat.cpp | 8 +++++++- .../kits/js/src/mod_fs/class_stream/fs_stream.cpp | 2 +- .../kits/js/src/mod_fs/class_watcher/fs_watcher.cpp | 2 +- .../kits/js/src/mod_fs/properties/access_core.cpp | 3 ++- .../kits/js/src/mod_fs/properties/close_core.cpp | 3 ++- .../kits/js/src/mod_fs/properties/fdatasync_core.cpp | 3 ++- .../kits/js/src/mod_fs/properties/fsync_core.cpp | 3 ++- .../kits/js/src/mod_fs/properties/mkdir_core.cpp | 6 ++++-- .../kits/js/src/mod_fs/properties/mkdtemp_core.cpp | 3 ++- .../kits/js/src/mod_fs/properties/movedir_core.cpp | 2 +- interfaces/kits/js/src/mod_fs/properties/open_core.cpp | 3 ++- interfaces/kits/js/src/mod_fs/properties/read_core.cpp | 3 ++- .../kits/js/src/mod_fs/properties/read_lines_core.cpp | 3 ++- .../kits/js/src/mod_fs/properties/read_text_core.cpp | 10 +++++++--- .../kits/js/src/mod_fs/properties/rename_core.cpp | 3 ++- .../kits/js/src/mod_fs/properties/symlink_core.cpp | 3 ++- .../kits/js/src/mod_fs/properties/truncate_core.cpp | 9 ++++++--- .../kits/js/src/mod_fs/properties/unlink_core.cpp | 3 ++- .../kits/js/src/mod_fs/properties/utimes_core.cpp | 3 ++- .../kits/js/src/mod_fs/properties/write_core.cpp | 3 ++- .../js/src/mod_hash/class_hashstream/hs_hashstream.cpp | 2 +- 25 files changed, 63 insertions(+), 31 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/class_atomicfile/fs_atomicfile.cpp b/interfaces/kits/js/src/mod_fs/class_atomicfile/fs_atomicfile.cpp index 2caa33889..6e7916931 100644 --- a/interfaces/kits/js/src/mod_fs/class_atomicfile/fs_atomicfile.cpp +++ b/interfaces/kits/js/src/mod_fs/class_atomicfile/fs_atomicfile.cpp @@ -226,7 +226,11 @@ FsResult FsAtomicFile::Constructor(string path) atomicFileEntity->baseFileName = path; atomicFileEntity->newFileName = path.append(TEMP_FILE_SUFFIX); - auto file = new FsAtomicFile(move(atomicFileEntity)); + auto file = new (std::nothrow) FsAtomicFile(move(atomicFileEntity)); + if (file == nullptr) { + HILOGE("Failed to create FsAtomicFile"); + return FsResult::Error(ENOMEM); + } return FsResult::Success(file); } diff --git a/interfaces/kits/js/src/mod_fs/class_file/fs_file.cpp b/interfaces/kits/js/src/mod_fs/class_file/fs_file.cpp index 830734643..54e69caff 100644 --- a/interfaces/kits/js/src/mod_fs/class_file/fs_file.cpp +++ b/interfaces/kits/js/src/mod_fs/class_file/fs_file.cpp @@ -194,7 +194,7 @@ FsResult FsFile::Constructor() return FsResult::Error(ENOMEM); } - FsFile *fsFilePtr = new FsFile(move(rafEntity)); + FsFile *fsFilePtr = new (std::nothrow) FsFile(move(rafEntity)); if (fsFilePtr == nullptr) { HILOGE("Failed to create FsFile object on heap."); return FsResult::Error(ENOMEM); diff --git a/interfaces/kits/js/src/mod_fs/class_randomaccessfile/fs_randomaccessfile.cpp b/interfaces/kits/js/src/mod_fs/class_randomaccessfile/fs_randomaccessfile.cpp index b7f9160e9..16fc7a8d4 100644 --- a/interfaces/kits/js/src/mod_fs/class_randomaccessfile/fs_randomaccessfile.cpp +++ b/interfaces/kits/js/src/mod_fs/class_randomaccessfile/fs_randomaccessfile.cpp @@ -240,7 +240,7 @@ FsResult FsRandomAccessFile::WriteSync(const ArrayBuffer &buffer, const static int CloseFd(int fd) { - unique_ptr closeReq = { new uv_fs_t, FsUtils::FsReqCleanup }; + unique_ptr closeReq = { new (nothrow) uv_fs_t, FsUtils::FsReqCleanup }; if (!closeReq) { HILOGE("Failed to request heap memory."); return ENOMEM; @@ -274,7 +274,7 @@ FsResult FsRandomAccessFile::Constructor() return FsResult::Error(ENOMEM); } - FsRandomAccessFile *randomAccessFilePtr = new FsRandomAccessFile(move(rafEntity)); + FsRandomAccessFile *randomAccessFilePtr = new (nothrow) FsRandomAccessFile(move(rafEntity)); if (randomAccessFilePtr == nullptr) { HILOGE("INNER BUG. Failed to wrap entity for obj RandomAccessFile"); return FsResult::Error(EIO); diff --git a/interfaces/kits/js/src/mod_fs/class_readeriterator/fs_reader_iterator.cpp b/interfaces/kits/js/src/mod_fs/class_readeriterator/fs_reader_iterator.cpp index 80321d51f..4057e1349 100644 --- a/interfaces/kits/js/src/mod_fs/class_readeriterator/fs_reader_iterator.cpp +++ b/interfaces/kits/js/src/mod_fs/class_readeriterator/fs_reader_iterator.cpp @@ -30,7 +30,7 @@ FsResult FsReaderIterator::Constructor() return FsResult::Error(ENOMEM); } - FsReaderIterator *it = new FsReaderIterator(move(entity)); + FsReaderIterator *it = new (nothrow) FsReaderIterator(move(entity)); if (it == nullptr) { HILOGE("Failed to create FsReaderIterator object on heap."); diff --git a/interfaces/kits/js/src/mod_fs/class_stat/fs_stat.cpp b/interfaces/kits/js/src/mod_fs/class_stat/fs_stat.cpp index 4094dce3b..4fa0a082e 100644 --- a/interfaces/kits/js/src/mod_fs/class_stat/fs_stat.cpp +++ b/interfaces/kits/js/src/mod_fs/class_stat/fs_stat.cpp @@ -165,7 +165,13 @@ FsStat *FsStat::Constructor() return nullptr; } - return new FsStat(move(entity)); + auto file = new (nothrow) FsStat(move(entity)); + if (file == nullptr) { + HILOGE("Failed to create FsStat."); + return nullptr; + } + + return file; } } // namespace OHOS::FileManagement::ModuleFileIO \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/class_stream/fs_stream.cpp b/interfaces/kits/js/src/mod_fs/class_stream/fs_stream.cpp index 00a493ed2..3494310aa 100644 --- a/interfaces/kits/js/src/mod_fs/class_stream/fs_stream.cpp +++ b/interfaces/kits/js/src/mod_fs/class_stream/fs_stream.cpp @@ -277,7 +277,7 @@ FsResult FsStream::Constructor() HILOGE("Failed to request heap memory."); return FsResult::Error(ENOMEM); } - FsStream *fsStreamPtr = new FsStream(move(rafEntity)); + FsStream *fsStreamPtr = new (nothrow) FsStream(move(rafEntity)); if (fsStreamPtr == nullptr) { HILOGE("Failed to create FsStream object on heap."); diff --git a/interfaces/kits/js/src/mod_fs/class_watcher/fs_watcher.cpp b/interfaces/kits/js/src/mod_fs/class_watcher/fs_watcher.cpp index 73dd1d830..f761620fa 100644 --- a/interfaces/kits/js/src/mod_fs/class_watcher/fs_watcher.cpp +++ b/interfaces/kits/js/src/mod_fs/class_watcher/fs_watcher.cpp @@ -32,7 +32,7 @@ FsResult FsWatcher::Constructor() return FsResult::Error(ENOMEM); } - FsWatcher *watcherPtr = new FsWatcher(move(watchEntity)); + FsWatcher *watcherPtr = new (nothrow) FsWatcher(move(watchEntity)); if (watcherPtr == nullptr) { HILOGE("Failed to create FsWatcher object on heap."); diff --git a/interfaces/kits/js/src/mod_fs/properties/access_core.cpp b/interfaces/kits/js/src/mod_fs/properties/access_core.cpp index bc6ae9ed5..ff9cc078c 100644 --- a/interfaces/kits/js/src/mod_fs/properties/access_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/access_core.cpp @@ -55,7 +55,8 @@ const int BASE_USER_RANGE = 200000; static int UvAccess(const string &path, int mode) { - std::unique_ptr accessReq = {new uv_fs_t, FsUtils::FsReqCleanup}; + std::unique_ptr accessReq = {new (nothrow) uv_fs_t, + FsUtils::FsReqCleanup}; if (!accessReq) { HILOGE("Failed to request heap memory."); return ENOMEM; diff --git a/interfaces/kits/js/src/mod_fs/properties/close_core.cpp b/interfaces/kits/js/src/mod_fs/properties/close_core.cpp index e71152fcc..72c1a7aa3 100644 --- a/interfaces/kits/js/src/mod_fs/properties/close_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/close_core.cpp @@ -27,7 +27,8 @@ using namespace std; static int32_t CloseFd(int fd) { - unique_ptr closeReq = { new uv_fs_t, FsUtils::FsReqCleanup }; + unique_ptr closeReq = { new (nothrow) uv_fs_t, + FsUtils::FsReqCleanup }; if (!closeReq) { HILOGE("Failed to request heap memory."); return ENOMEM; diff --git a/interfaces/kits/js/src/mod_fs/properties/fdatasync_core.cpp b/interfaces/kits/js/src/mod_fs/properties/fdatasync_core.cpp index 8db58a390..746484bbd 100644 --- a/interfaces/kits/js/src/mod_fs/properties/fdatasync_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/fdatasync_core.cpp @@ -27,7 +27,8 @@ namespace OHOS::FileManagement::ModuleFileIO { FsResult FDataSyncCore::DoFDataSync(const int32_t &fd) { - std::unique_ptr fDataSyncReq = { new uv_fs_t, FsUtils::FsReqCleanup }; + std::unique_ptr fDataSyncReq = { new (std::nothrow) uv_fs_t, + FsUtils::FsReqCleanup }; if (!fDataSyncReq) { HILOGE("Failed to request heap memory."); return FsResult::Error(ENOMEM); diff --git a/interfaces/kits/js/src/mod_fs/properties/fsync_core.cpp b/interfaces/kits/js/src/mod_fs/properties/fsync_core.cpp index 9fe16f3ea..4f9f26fc3 100644 --- a/interfaces/kits/js/src/mod_fs/properties/fsync_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/fsync_core.cpp @@ -27,7 +27,8 @@ using namespace std; FsResult FsyncCore::DoFsync(const int32_t &fd) { - std::unique_ptr fsyncReq = { new uv_fs_t, FsUtils::FsReqCleanup }; + std::unique_ptr fsyncReq = { new (std::nothrow) uv_fs_t, + FsUtils::FsReqCleanup }; if (!fsyncReq) { HILOGE("Failed to request heap memory."); return FsResult::Error(ENOMEM); diff --git a/interfaces/kits/js/src/mod_fs/properties/mkdir_core.cpp b/interfaces/kits/js/src/mod_fs/properties/mkdir_core.cpp index 3e21316a8..3d777f610 100644 --- a/interfaces/kits/js/src/mod_fs/properties/mkdir_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/mkdir_core.cpp @@ -39,7 +39,8 @@ using namespace std; static int UvAccess(const string &path, int mode) { - std::unique_ptr accessReq = { new uv_fs_t, FsUtils::FsReqCleanup }; + std::unique_ptr accessReq = { new (std::nothrow) uv_fs_t, + FsUtils::FsReqCleanup }; if (!accessReq) { HILOGE("Failed to request heap memory."); return ENOMEM; @@ -50,7 +51,8 @@ static int UvAccess(const string &path, int mode) static int MkdirCore(const string &path) { - std::unique_ptr mkdirReq = { new uv_fs_t, FsUtils::FsReqCleanup }; + std::unique_ptr mkdirReq = { new (std::nothrow) uv_fs_t, + FsUtils::FsReqCleanup }; if (!mkdirReq) { HILOGE("Failed to request heap memory."); return ENOMEM; diff --git a/interfaces/kits/js/src/mod_fs/properties/mkdtemp_core.cpp b/interfaces/kits/js/src/mod_fs/properties/mkdtemp_core.cpp index 1530b9583..5e6384c94 100644 --- a/interfaces/kits/js/src/mod_fs/properties/mkdtemp_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/mkdtemp_core.cpp @@ -25,7 +25,8 @@ using namespace std; FsResult MkdtempCore::DoMkdtemp(const string &path) { - unique_ptr mkdtempReq = { new uv_fs_t, FsUtils::FsReqCleanup }; + unique_ptr mkdtempReq = { new (std::nothrow) uv_fs_t, + FsUtils::FsReqCleanup }; if (!mkdtempReq) { HILOGE("Failed to request heap memory."); return FsResult::Error(ENOMEM); diff --git a/interfaces/kits/js/src/mod_fs/properties/movedir_core.cpp b/interfaces/kits/js/src/mod_fs/properties/movedir_core.cpp index 172c631b7..bd355c6fd 100644 --- a/interfaces/kits/js/src/mod_fs/properties/movedir_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/movedir_core.cpp @@ -183,7 +183,7 @@ static int RecurMoveDir(const string &srcPath, const string &destPath, const int return ERRNO_NOERR; } - unique_ptr ptr = {new struct NameListArg, Deleter}; + unique_ptr ptr = {new (std::nothrow) struct NameListArg, Deleter}; if (!ptr) { HILOGE("Failed to request heap memory."); return ENOMEM; diff --git a/interfaces/kits/js/src/mod_fs/properties/open_core.cpp b/interfaces/kits/js/src/mod_fs/properties/open_core.cpp index 04a2bb1cd..6b9b1edde 100644 --- a/interfaces/kits/js/src/mod_fs/properties/open_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/open_core.cpp @@ -87,7 +87,8 @@ static tuple ValidAndConvertFlags(const optional &mode) static int OpenFileByPath(const string &path, uint32_t mode) { - unique_ptr openReq = { new uv_fs_t, FsUtils::FsReqCleanup }; + unique_ptr openReq = { new (std::nothrow) uv_fs_t, + FsUtils::FsReqCleanup }; if (!openReq) { HILOGE("Failed to request heap memory."); return -ENOMEM; diff --git a/interfaces/kits/js/src/mod_fs/properties/read_core.cpp b/interfaces/kits/js/src/mod_fs/properties/read_core.cpp index 2099ebce6..72f8bcf9e 100644 --- a/interfaces/kits/js/src/mod_fs/properties/read_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/read_core.cpp @@ -75,7 +75,8 @@ FsResult ReadCore::DoRead(const int32_t &fd, ArrayBuffer &arrayBuffer, } uv_buf_t buffer = uv_buf_init(static_cast(buf), static_cast(len)); - unique_ptr readReq = { new uv_fs_t, FsUtils::FsReqCleanup }; + unique_ptr readReq = { new (std::nothrow) uv_fs_t, + FsUtils::FsReqCleanup }; if (!readReq) { HILOGE("Failed to request heap memory."); return FsResult::Error(ENOMEM); diff --git a/interfaces/kits/js/src/mod_fs/properties/read_lines_core.cpp b/interfaces/kits/js/src/mod_fs/properties/read_lines_core.cpp index 1f9869151..104d27e4c 100644 --- a/interfaces/kits/js/src/mod_fs/properties/read_lines_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/read_lines_core.cpp @@ -37,7 +37,8 @@ static int CheckOptionArg(Options option) static int GetFileSize(const string &path, int64_t &offset) { - std::unique_ptr readLinesReq = { new uv_fs_t, FsUtils::FsReqCleanup }; + std::unique_ptr readLinesReq = { new (std::nothrow) uv_fs_t, + FsUtils::FsReqCleanup }; if (!readLinesReq) { HILOGE("Failed to request heap memory."); return ENOMEM; diff --git a/interfaces/kits/js/src/mod_fs/properties/read_text_core.cpp b/interfaces/kits/js/src/mod_fs/properties/read_text_core.cpp index 90b1b7109..092cb2af7 100644 --- a/interfaces/kits/js/src/mod_fs/properties/read_text_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/read_text_core.cpp @@ -34,7 +34,11 @@ static tuple> ValidReadTextArg( int64_t offset = -1; int64_t len = 0; bool hasLen = false; - unique_ptr encoding { new char[]{ "utf-8" } }; + unique_ptr encoding { new (std::nothrow) char[]{ "utf-8" } }; + if(!encoding){ + HILOGE("Failed to request heap memory."); + return { false, offset, hasLen, len, nullptr }; + } if (!options.has_value()) { return { true, offset, hasLen, len, move(encoding) }; @@ -72,7 +76,7 @@ static tuple> ValidReadTextArg( static int OpenFile(const std::string& path) { std::unique_ptr openReq = { - new uv_fs_t, FsUtils::FsReqCleanup + new (std::nothrow) uv_fs_t, FsUtils::FsReqCleanup }; if (openReq == nullptr) { HILOGE("Failed to request heap memory."); @@ -87,7 +91,7 @@ static int ReadFromFile(int fd, int64_t offset, string& buffer) { uv_buf_t readbuf = uv_buf_init(const_cast(buffer.c_str()), static_cast(buffer.size())); std::unique_ptr readReq = { - new uv_fs_t, FsUtils::FsReqCleanup }; + new (std::nothrow) uv_fs_t, FsUtils::FsReqCleanup }; if (readReq == nullptr) { HILOGE("Failed to request heap memory."); return -ENOMEM; diff --git a/interfaces/kits/js/src/mod_fs/properties/rename_core.cpp b/interfaces/kits/js/src/mod_fs/properties/rename_core.cpp index 1edff30a2..0f925d06c 100644 --- a/interfaces/kits/js/src/mod_fs/properties/rename_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/rename_core.cpp @@ -29,7 +29,8 @@ using namespace std; FsResult RenameCore::DoRename(const string &src, const string &dest) { - std::unique_ptr renameReq = { new uv_fs_t, FsUtils::FsReqCleanup }; + std::unique_ptr renameReq = { new (std::nothrow) uv_fs_t, + FsUtils::FsReqCleanup }; if (!renameReq) { HILOGE("Failed to request heap memory."); return FsResult::Error(ENOMEM); diff --git a/interfaces/kits/js/src/mod_fs/properties/symlink_core.cpp b/interfaces/kits/js/src/mod_fs/properties/symlink_core.cpp index 217f429fd..ed860bd6a 100644 --- a/interfaces/kits/js/src/mod_fs/properties/symlink_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/symlink_core.cpp @@ -30,7 +30,8 @@ using namespace std; FsResult SymlinkCore::DoSymlink(const string &target, const string &srcPath) { - std::unique_ptr symlinkReq = { new uv_fs_t, FsUtils::FsReqCleanup }; + std::unique_ptr symlinkReq = { new (std::nothrow) uv_fs_t, + FsUtils::FsReqCleanup }; if (!symlinkReq) { HILOGE("Failed to request heap memory."); return FsResult::Error(ENOMEM); diff --git a/interfaces/kits/js/src/mod_fs/properties/truncate_core.cpp b/interfaces/kits/js/src/mod_fs/properties/truncate_core.cpp index 977c660aa..8f9464609 100644 --- a/interfaces/kits/js/src/mod_fs/properties/truncate_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/truncate_core.cpp @@ -40,7 +40,8 @@ static bool ValidFileInfo(FileInfo &fileInfo) static int Truncate(FileInfo &fileInfo, int64_t truncateLen) { if (fileInfo.isPath) { - unique_ptr openReq = { new uv_fs_t, FsUtils::FsReqCleanup }; + unique_ptr openReq = { new (nothrow) uv_fs_t, + FsUtils::FsReqCleanup }; if (!openReq) { HILOGE("Failed to request heap memory."); return ENOMEM; @@ -50,7 +51,8 @@ static int Truncate(FileInfo &fileInfo, int64_t truncateLen) if (ret < 0) { return ret; } - unique_ptr ftruncateReq = { new uv_fs_t, FsUtils::FsReqCleanup }; + unique_ptr ftruncateReq = { new (nothrow) uv_fs_t, + FsUtils::FsReqCleanup }; if (!ftruncateReq) { HILOGE("Failed to request heap memory."); return ENOMEM; @@ -61,7 +63,8 @@ static int Truncate(FileInfo &fileInfo, int64_t truncateLen) return ret; } } else { - unique_ptr ftruncateReq = { new uv_fs_t, FsUtils::FsReqCleanup }; + unique_ptr ftruncateReq = { new (nothrow) uv_fs_t, + FsUtils::FsReqCleanup }; if (!ftruncateReq) { HILOGE("Failed to request heap memory."); return ENOMEM; diff --git a/interfaces/kits/js/src/mod_fs/properties/unlink_core.cpp b/interfaces/kits/js/src/mod_fs/properties/unlink_core.cpp index cff5a2af7..2b6d35e50 100644 --- a/interfaces/kits/js/src/mod_fs/properties/unlink_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/unlink_core.cpp @@ -28,7 +28,8 @@ using namespace std; FsResult UnlinkCore::DoUnlink(const string &src) { - unique_ptr unlinkReq = { new uv_fs_t, FsUtils::FsReqCleanup }; + unique_ptr unlinkReq = { + new (nothrow) uv_fs_t, FsUtils::FsReqCleanup }; if (!unlinkReq) { HILOGE("Failed to request heap memory."); return FsResult::Error(ENOMEM); diff --git a/interfaces/kits/js/src/mod_fs/properties/utimes_core.cpp b/interfaces/kits/js/src/mod_fs/properties/utimes_core.cpp index bc110b2f5..b26ed6d6b 100644 --- a/interfaces/kits/js/src/mod_fs/properties/utimes_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/utimes_core.cpp @@ -42,7 +42,8 @@ FsResult UtimesCore::DoUtimes(const string &path, const double mtime) return FsResult::Error(ret); } - unique_ptr utimesReq = { new uv_fs_t, FsUtils::FsReqCleanup }; + unique_ptr utimesReq = { + new (nothrow) uv_fs_t, FsUtils::FsReqCleanup }; if (!utimesReq) { HILOGE("Failed to request heap memory."); return FsResult::Error(ENOMEM); diff --git a/interfaces/kits/js/src/mod_fs/properties/write_core.cpp b/interfaces/kits/js/src/mod_fs/properties/write_core.cpp index b3f8c61a7..ec04b6bc3 100644 --- a/interfaces/kits/js/src/mod_fs/properties/write_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/write_core.cpp @@ -113,7 +113,8 @@ FsResult WriteCore::DoWrite(const int32_t fd, const ArrayBuffer &buffer FsResult WriteCore::DoWrite(const int32_t fd, void *buf, const size_t len, const int64_t offset) { uv_buf_t buffer = uv_buf_init(static_cast(buf), static_cast(len)); - unique_ptr writeReq = { new uv_fs_t, FsUtils::FsReqCleanup }; + unique_ptr writeReq = { new (std::nothrow) uv_fs_t, + FsUtils::FsReqCleanup }; if (!writeReq) { return FsResult::Error(ENOMEM); } diff --git a/interfaces/kits/js/src/mod_hash/class_hashstream/hs_hashstream.cpp b/interfaces/kits/js/src/mod_hash/class_hashstream/hs_hashstream.cpp index b03eb2b15..e33f01bed 100644 --- a/interfaces/kits/js/src/mod_hash/class_hashstream/hs_hashstream.cpp +++ b/interfaces/kits/js/src/mod_hash/class_hashstream/hs_hashstream.cpp @@ -147,7 +147,7 @@ FsResult HsHashStream::Constructor(string alg) break; } - HsHashStream *hsStreamPtr = new HsHashStream(move(hsEntity)); + HsHashStream *hsStreamPtr = new (std::nothrow) HsHashStream(move(hsEntity)); if (hsStreamPtr == nullptr) { HILOGE("Failed to create HsHashStream object on heap."); return FsResult::Error(ENOMEM); -- Gitee From cce7fd3a7c7add82ebece9946ac1891004d87a8b Mon Sep 17 00:00:00 2001 From: wuchengjun Date: Mon, 18 Aug 2025 14:07:40 +0000 Subject: [PATCH 2/2] update interfaces/kits/js/src/mod_fs/properties/read_text_core.cpp. Signed-off-by: wuchengjun --- interfaces/kits/js/src/mod_fs/properties/read_text_core.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/read_text_core.cpp b/interfaces/kits/js/src/mod_fs/properties/read_text_core.cpp index 092cb2af7..2f9328f1c 100644 --- a/interfaces/kits/js/src/mod_fs/properties/read_text_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/read_text_core.cpp @@ -35,7 +35,7 @@ static tuple> ValidReadTextArg( int64_t len = 0; bool hasLen = false; unique_ptr encoding { new (std::nothrow) char[]{ "utf-8" } }; - if(!encoding){ + if (!encoding) { HILOGE("Failed to request heap memory."); return { false, offset, hasLen, len, nullptr }; } -- Gitee