diff --git a/interfaces/kits/js/src/mod_fs/common_func.cpp b/interfaces/kits/js/src/mod_fs/common_func.cpp index 092a9523881d7011333a4b741dfcf144473920ed..a71cbaf694d0f45bb029ac6fe4cd2f86ef75036e 100644 --- a/interfaces/kits/js/src/mod_fs/common_func.cpp +++ b/interfaces/kits/js/src/mod_fs/common_func.cpp @@ -247,10 +247,7 @@ NVal CommonFunc::InstantiateStream(napi_env env, unique_ptr(srcFd, true); auto destFdg = CreateUniquePtr(destFd, true); - std::unique_ptr sendFileReq = { - new (nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; - if (sendFileReq == nullptr) { - HILOGE("Failed to request heap memory."); - return ENOMEM; - } + uv_fs_t sendFileReq; int64_t offset = 0; struct stat srcStat{}; if (fstat(srcFdg->GetFD(), &srcStat) < 0) { @@ -171,6 +166,7 @@ int Copy::CopyFile(const string &src, const string &dest) offset, MAX_SIZE, nullptr); if (ret < 0) { HILOGE("Failed to sendfile by errno : %{public}d", errno); + uv_fs_req_cleanup(&sendFileReq); return errno; } offset += static_cast(ret); @@ -179,6 +175,7 @@ int Copy::CopyFile(const string &src, const string &dest) break; } } + uv_fs_req_cleanup(&sendFileReq); if (size != 0) { HILOGE("The execution of the sendfile task was terminated, remaining file size %{public}" PRIu64, size); return E_IO; diff --git a/interfaces/test/unittest/napi_test/FsCopyTest.js b/interfaces/test/unittest/napi_test/FsCopyTest.js index 996e89626aae8714a4703f1eed31a15c2e378b4a..f9bfb1b42419439dffc5073c17b0bb141c2d7f53 100644 --- a/interfaces/test/unittest/napi_test/FsCopyTest.js +++ b/interfaces/test/unittest/napi_test/FsCopyTest.js @@ -274,15 +274,14 @@ describe("FsCopyTest", function () { console.info(TAG, "Fs_Copy_Test008 success. "); expect(true).assertTrue(); } + fs.rmdirSync(srcDirPathLocal); + fs.rmdirSync(dstDirPathLocal); done(); }) } catch (err) { console.error("Fs_Copy_Test008 failed with invalid param: " + err.message + ", error code: " + err.code); expect().assertFail(); done(); - } finally { - fs.rmdirSync(srcDirPathLocal); - fs.rmdirSync(dstDirPathLocal); } }); diff --git a/interfaces/test/unittest/napi_test/config.json b/interfaces/test/unittest/napi_test/config.json index 651407b028fe013724f7730a4c8fa7f8cd7e0be8..bc919eb1d092d00acff47b00b04b22be24bc6078 100644 --- a/interfaces/test/unittest/napi_test/config.json +++ b/interfaces/test/unittest/napi_test/config.json @@ -1,6 +1,6 @@ { "app": { - "bundleName": "com.example.myapplication", + "bundleName": "com.example.fileapitest", "vendor": "example", "version": { "code": 1, @@ -13,7 +13,7 @@ }, "deviceConfig": {}, "module": { - "package": "com.example.myapplication", + "package": "com.example.fileapitest", "name": ".MyApplication", "deviceType": [ "default", @@ -38,7 +38,7 @@ ] } ], - "name": "com.example.myapplication.MainAbility", + "name": "com.example.fileapitest.MainAbility", "icon": "$media:icon", "description": "$string:mainability_description", "label": "MyApplication", diff --git a/interfaces/test/unittest/napi_test/openharmony_sx.p7b b/interfaces/test/unittest/napi_test/openharmony_sx.p7b index 166e7985b623f7bf896e6363761bb1a331c54db7..44ea389131964466987601324eaf0f52837cf462 100644 Binary files a/interfaces/test/unittest/napi_test/openharmony_sx.p7b and b/interfaces/test/unittest/napi_test/openharmony_sx.p7b differ