From 1985123774b3bd2a19641183b3567a265b93392c Mon Sep 17 00:00:00 2001 From: lixiyuan Date: Wed, 4 Dec 2024 23:53:26 +0800 Subject: [PATCH 1/3] =?UTF-8?q?pc=E5=91=8A=E8=AD=A6=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixiyuan --- services/storage_daemon/crypto/src/base_key.cpp | 2 +- services/storage_daemon/ipc/src/storage_daemon.cpp | 2 +- services/storage_daemon/mtpfs/src/mtpfs_fuse.cpp | 8 +++++--- services/storage_daemon/mtpfs/src/mtpfs_mtp_device.cpp | 6 +++--- .../storage/src/storage_monitor_service.cpp | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/services/storage_daemon/crypto/src/base_key.cpp b/services/storage_daemon/crypto/src/base_key.cpp index bc053ca6..d29b2ebd 100644 --- a/services/storage_daemon/crypto/src/base_key.cpp +++ b/services/storage_daemon/crypto/src/base_key.cpp @@ -697,7 +697,7 @@ bool BaseKey::DoRestoreKey(const UserAuth &auth, const std::string &path) std::error_code errCode; std::string need_restore; LoadStringFromFile(path + SUFFIX_NEED_RESTORE, need_restore); - uint32_t restore_version = std::atoi(need_restore.c_str()); + uint32_t restore_version = static_cast(std::atoi(need_restore.c_str())); UpdateVersion update_version = static_cast(std::atoi(need_restore.c_str())); LOGI("NeedRestore Path is: %{public}s, restore_version: %{public}u", path.c_str(), restore_version); if (std::filesystem::exists(path + SUFFIX_NEED_RESTORE, errCode)) { diff --git a/services/storage_daemon/ipc/src/storage_daemon.cpp b/services/storage_daemon/ipc/src/storage_daemon.cpp index ab92fc1e..e9613feb 100644 --- a/services/storage_daemon/ipc/src/storage_daemon.cpp +++ b/services/storage_daemon/ipc/src/storage_daemon.cpp @@ -694,7 +694,7 @@ int32_t StorageDaemon::PrepareUserDirsAndUpdateUserAuthVx(uint32_t userId, KeyTy return ret; } std::string need_restore_path = KeyManager::GetInstance()->GetKeyDirByUserAndType(userId, type) + RESTORE_DIR; - uint32_t new_need_restore = std::atoi(needRestoreVersion.c_str()) + 1; + uint32_t new_need_restore = static_cast(std::atoi(needRestoreVersion.c_str()) + 1); if (new_need_restore == UpdateVersion::UPDATE_V4 && !SaveStringToFileSync(need_restore_path, std::to_string(new_need_restore))) { LOGE("Write userId: %{public}d, El%{public}d need_restore failed.", userId, type); diff --git a/services/storage_daemon/mtpfs/src/mtpfs_fuse.cpp b/services/storage_daemon/mtpfs/src/mtpfs_fuse.cpp index 18a475c0..adc64888 100644 --- a/services/storage_daemon/mtpfs/src/mtpfs_fuse.cpp +++ b/services/storage_daemon/mtpfs/src/mtpfs_fuse.cpp @@ -579,7 +579,7 @@ int MtpFileSystem::ReName(const char *path, const char *newpath, unsigned int fl const int32_t factor = 1000; auto now = std::chrono::system_clock::now(); auto millisecs = std::chrono::duration_cast(now.time_since_epoch()); - uint64_t time = millisecs.count() / factor; + time_t time = static_cast(millisecs.count() / factor); if (dirParent != nullptr) { LOGI("MtpFileSystem: file cutted, update dirParent mtime"); const_cast(dirParent)->SetModificationDate(time); @@ -689,9 +689,11 @@ int MtpFileSystem::Open(const char *path, struct fuse_file_info *fileInfo) LOGE("Missing FileInfo"); return -ENOENT; } - if (static_cast(fileInfo->flags) & O_WRONLY) { - static_cast(fileInfo->flags) |= O_TRUNC; + unsigned int flags = static_cast(fileInfo->flags); + if (flags & O_WRONLY) { + flags |= O_TRUNC; } + fileInfo->flags = static_cast(flags); const std::string stdPath(path); MtpFsTypeTmpFile *tmpFile = const_cast(tmpFilesPool_.GetFile(stdPath)); diff --git a/services/storage_daemon/mtpfs/src/mtpfs_mtp_device.cpp b/services/storage_daemon/mtpfs/src/mtpfs_mtp_device.cpp index 56f396ae..37e8f0dc 100644 --- a/services/storage_daemon/mtpfs/src/mtpfs_mtp_device.cpp +++ b/services/storage_daemon/mtpfs/src/mtpfs_mtp_device.cpp @@ -277,11 +277,11 @@ const MtpFsTypeDir *MtpFsDevice::DirFetchContent(std::string path) static uint64_t GetFormattedTimestamp() { - const int32_t secFactor = 1000; + const int64_t secFactor = 1000; auto now = std::chrono::system_clock::now(); auto millisecs = std::chrono::duration_cast(now.time_since_epoch()); - uint64_t milliSeconds = millisecs.count(); - return milliSeconds / secFactor; + uint64_t milliSeconds = static_cast(millisecs.count() / secFactor); + return milliSeconds; } int MtpFsDevice::DirCreateNew(const std::string &path) diff --git a/services/storage_manager/storage/src/storage_monitor_service.cpp b/services/storage_manager/storage/src/storage_monitor_service.cpp index 597ac333..d3f355f0 100644 --- a/services/storage_manager/storage/src/storage_monitor_service.cpp +++ b/services/storage_manager/storage/src/storage_monitor_service.cpp @@ -182,7 +182,7 @@ void StorageMonitorService::CleanBundleCacheByInterval(const std::string ×t LOGI("Not found timestamp from system parameter"); return; } - uint64_t lastCleanCacheTime = std::stoull(param); + uint64_t lastCleanCacheTime = static_cast(std::atoull(param.c_str())); auto duration = std::chrono::duration_cast(currentTime - std::chrono::system_clock::time_point(std::chrono::hours(lastCleanCacheTime))).count(); LOGI("CleanBundleCache timestamp is %{public}s, duration is %{public}ld", timestamp.c_str(), duration); -- Gitee From 8b6e1745e58781f61c7ada42d5b1df0990771029 Mon Sep 17 00:00:00 2001 From: lixiyuan Date: Thu, 5 Dec 2024 17:03:10 +0800 Subject: [PATCH 2/3] =?UTF-8?q?memory=20leak=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixiyuan --- services/storage_daemon/mtpfs/src/mtpfs_util.cpp | 1 + .../storage_manager/storage/src/storage_monitor_service.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/services/storage_daemon/mtpfs/src/mtpfs_util.cpp b/services/storage_daemon/mtpfs/src/mtpfs_util.cpp index baf476a0..007a334c 100644 --- a/services/storage_daemon/mtpfs/src/mtpfs_util.cpp +++ b/services/storage_daemon/mtpfs/src/mtpfs_util.cpp @@ -141,6 +141,7 @@ std::string SmtpfsGetTmpDir() } tmpDir.assign(cTmpDir); ::free(static_cast(cTmpDirFree)); + ::free(static_cast(cTmpDir)); return tmpDir; } diff --git a/services/storage_manager/storage/src/storage_monitor_service.cpp b/services/storage_manager/storage/src/storage_monitor_service.cpp index d3f355f0..77e298dd 100644 --- a/services/storage_manager/storage/src/storage_monitor_service.cpp +++ b/services/storage_manager/storage/src/storage_monitor_service.cpp @@ -182,7 +182,7 @@ void StorageMonitorService::CleanBundleCacheByInterval(const std::string ×t LOGI("Not found timestamp from system parameter"); return; } - uint64_t lastCleanCacheTime = static_cast(std::atoull(param.c_str())); + uint64_t lastCleanCacheTime = static_cast(std::atoll(param.c_str())); auto duration = std::chrono::duration_cast(currentTime - std::chrono::system_clock::time_point(std::chrono::hours(lastCleanCacheTime))).count(); LOGI("CleanBundleCache timestamp is %{public}s, duration is %{public}ld", timestamp.c_str(), duration); -- Gitee From 974681daa7bfe642fbcfa6c2a316c40cee337922 Mon Sep 17 00:00:00 2001 From: lixiyuan Date: Thu, 5 Dec 2024 22:00:35 +0800 Subject: [PATCH 3/3] =?UTF-8?q?memory=20leak=E9=97=AE=E9=A2=98=E9=87=8D?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixiyuan --- .../storage_daemon/mtpfs/src/mtpfs_util.cpp | 23 ++----------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/services/storage_daemon/mtpfs/src/mtpfs_util.cpp b/services/storage_daemon/mtpfs/src/mtpfs_util.cpp index 007a334c..c5fa8db7 100644 --- a/services/storage_daemon/mtpfs/src/mtpfs_util.cpp +++ b/services/storage_daemon/mtpfs/src/mtpfs_util.cpp @@ -119,28 +119,9 @@ std::string SmtpfsGetTmpDir() { const char *cTmp = "/data/local/mtp_tmp"; OHOS::StorageDaemon::DelTemp(cTmp); - std::string tmpDir; - if (cTmp) { - tmpDir = SmtpfsRealPath(cTmp); - } else { - cTmp = getenv("TMPDIR"); - if (!cTmp) { - cTmp = TMPDIR; - } - tmpDir = SmtpfsRealPath(cTmp); - } - tmpDir += "/simple-mtpfs-XXXXXX"; - char *cTmpDir = ::strdup(tmpDir.c_str()); - if (cTmpDir == nullptr) { - return ""; - } - char *cTmpDirFree = ::mkdtemp(cTmpDir); - if (cTmpDirFree == nullptr) { - ::free(static_cast(cTmpDir)); - return ""; - } + std::string tmpDir = SmtpfsRealPath(cTmp) + "/simple-mtpfs-XXXXXX"; + char *cTmpDir = ::mkdtemp(::strdup(tmpDir.c_str())); tmpDir.assign(cTmpDir); - ::free(static_cast(cTmpDirFree)); ::free(static_cast(cTmpDir)); return tmpDir; } -- Gitee