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 2caa33889b4355e772b956cb41798fe94bbb0e53..6e7916931908ddb389da090fdbf5ac71006dc55e 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 8307346437284e6548e8faca9f62fda29f64c979..54e69caffcea2afe823e8de840f8b6c394f6adaf 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 b7f9160e952020bb9113caf98605ea8e590b998a..16fc7a8d4cfaed2629d450710badbd1750e16b0f 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 80321d51f126f318d7ae4fd8c78ba76db64ff928..4057e1349ebf9cd3e1c5d63c04d2a55c50593adb 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 4094dce3b003f1148ed358e841c354fcff3ddffd..4fa0a082ea589b59e5193566e4750aa4c1ee34c1 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 00a493ed2767ee19c5128f27ae62b8df9fcf6eff..3494310aac3df25d8691681d1007d66a35d20bd0 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 73dd1d8303a3f99aa1c7895778b85db513630b17..f761620fa5b6a42de00720305c97046775a8d2c5 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 bc6ae9ed5efbcd36a285a472807304ff3d306b19..c7ddbb8acab750a592da30f41460cf7117726f84 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 e71152fcc164fedba4f72234f214d9bdb210ddcf..72c1a7aa342705b582b51c79cac9d2b570d131df 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 8db58a3908693b4416e4858cae07f9e8f03cf595..746484bbd3209f8099d901f63f1bd0670415abb0 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 9fe16f3eae033b14a1e4576a40a1f918af58afd7..4f9f26fc3f5ea2924f8ac8920b266cc838939196 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 3e21316a8734d08de699bcfe137ff033e1ed46a2..3d777f61084299d9af60fe38cf0d6c0790e287b3 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 1530b958353901104aca755b77e8adb000bd3b76..5e6384c9452ad20aa9c59d811124ae4daf443733 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 172c631b7385e14a441f633ac5aec55bd79e6623..f32afb671c4b0d4d05baf0a9cc2b2a24af383370 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 04a2bb1cdd48b2252b6daefcf67723bc804d5de3..6b9b1edde87d6394347f488ab5c7b7336a5189da 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 2099ebce63eb8ca42436d1a78e60305fc5247ad7..72f8bcf9e3061991b1f69236174f3fb3da3397eb 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 1f986915199031de14d6eedf10ebb6115003e9c6..104d27e4c0f05689af660f1f3e7b52c85f75751a 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 90b1b71095eca8e106dad4fa14cd74ac48a44d30..2f9328f1cee5870e3baeab2d2de7c30d1bdeb19f 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 1edff30a2084d8e8f6387358103de195ac7aa3fa..0f925d06c49bbd627c77a706792e53981407c755 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 217f429fd20e7a4e1c8b53fbbfbd3bdb4f067010..ed860bd6a9f183ced466578bc3816d2cb0853759 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 977c660aa3fe7e7aa870441f00948f0e171f727f..8f94646093fd1b776e6b366fb6324f93dca1d35c 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 cff5a2af721a3520c2fadc6c4aec899123467e35..2b6d35e5064fa2d5515c3e22739ab4cd54e9c17e 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 bc110b2f52c3dd2504a6fad3b763026faceedb49..b26ed6d6b0ef4a0fd88741d28be9e7f3091d257c 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 b3f8c61a768719b3483314a36d6f25ac3803fee5..ec04b6bc36644aabbb24745ba39115da70804837 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 b03eb2b15e9f1ed4e8c34f50095039b56808e11e..e33f01bedb0a575d50c93f4177a492e07e247f8e 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);