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); } }