Protect Against Potential Memory L eak and IWYU Cleanups#813
Open
JHartzer wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR resolves a potential memory leak identified via static analysis in the Linux backend. It also implements several IWYU header fixes.
Problems Identified
linux/hid.cparse_uevent_infowhere multiple matchingHID_UNIQorHID_NAMEkeys in aueventfile could overwrite previously allocated buffers without freeing them first.libusb/hid.candmac/hid.c) relied on transitive inclusions for standard types likeuint8_t, standard functions likecalloc, and error definitions likeerrno. If parent headers are refactored, these sources will break.<sys/utsname.h>and<linux/version.h>) were included in multiple places, unnecessarily increasing compile times.Proposed Changes
linux/hid.cto safely free any previously allocated memory before saving a new device property. This stops memory from leaking if a device's info key (like name or serial) is parsed more than once.<stdint.h>,<stdlib.h>, and<errno.h>) across the test utility, macOS, and LibUSB backends so they don't crash or break when parent files are updated.<sys/utsname.h>and<linux/version.h>) that were cluttering the code and slowing down compile times.Verification & Testing
1. Automated Compilation
Clean out-of-source builds were configured and executed using CMake:
2. Static Analysis
A verification pass using clang-tidy was conducted on the Linux backend:
clang-tidy -p build-tidy linux/hid.c3. Functional Verification
The compiled test utility
hidtest_hidrawwas run successfully. It executed thehid_enumerate()discovery loop using our modifiedparse_uevent_infoimplementation, successfully extracting and displaying all connected USB device attributes