From 32e2ab08e68eddc15c5fa9890a323949f07537d6 Mon Sep 17 00:00:00 2001 From: hwzhangchuang Date: Sat, 13 Jul 2024 15:03:46 +0800 Subject: [PATCH 1/2] modify not release fd Signed-off-by: hwzhangchuang --- utils/src/dinput_utils_tool.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils/src/dinput_utils_tool.cpp b/utils/src/dinput_utils_tool.cpp index a6e99fa..0ddfe37 100644 --- a/utils/src/dinput_utils_tool.cpp +++ b/utils/src/dinput_utils_tool.cpp @@ -268,7 +268,7 @@ std::string Sha256(const std::string &in) return reinterpret_cast(out); } -void CloseFd(int fd) +void CloseFd(int &fd) { if (fd < 0) { DHLOGE("No fd need to beclosed."); @@ -403,6 +403,7 @@ void ResetVirtualDevicePressedKeys(const std::vector &nodePaths) int rc = ioctl(fd, EVIOCGKEY(sizeof(keyState)), keyState); if (rc < 0) { DHLOGE("Read all key state failed, rc: %{public}d, path: %{public}s", rc, path.c_str()); + CloseFd(fd); continue; } @@ -414,6 +415,7 @@ void ResetVirtualDevicePressedKeys(const std::vector &nodePaths) } if (pressedKeys.empty()) { + CloseFd(fd); continue; } @@ -430,6 +432,7 @@ void ResetVirtualDevicePressedKeys(const std::vector &nodePaths) event.code = 0; WriteEventToDevice(fd, event); } + CloseFd(fd); } } -- Gitee From 900169fd4d597778cb0271ebf5536bc4c3557027 Mon Sep 17 00:00:00 2001 From: hwzhangchuang Date: Sat, 13 Jul 2024 16:26:43 +0800 Subject: [PATCH 2/2] add Signed-off-by: hwzhangchuang --- utils/include/dinput_utils_tool.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/include/dinput_utils_tool.h b/utils/include/dinput_utils_tool.h index 1a9e7cc..01d0d6c 100644 --- a/utils/include/dinput_utils_tool.h +++ b/utils/include/dinput_utils_tool.h @@ -51,7 +51,7 @@ std::string GetNodeDesc(std::string parameters); std::string GetAnonyString(const std::string &value); std::string GetAnonyInt32(const int32_t value); std::string Sha256(const std::string &string); -void CloseFd(int fd); +void CloseFd(int &fd); int BitIsSet(const unsigned long *array, int bit); void SplitStringToVector(const std::string &str, const char split, std::vector &vecStr); int OpenInputDeviceFdByPath(const std::string &devicePath); -- Gitee