Repository navigation
Conversation
Check every allocation in the descriptor reconstructor and propagate list node allocation failures. Add a single null-safe cleanup path for partial allocations, including the previously leaked coll_last_written_child. Keep list insertion small by reusing rd_append_main_item_node and restoring the detached next pointer if allocation fails. Keep coll_parsed_flag, coll_last_written_child and the last lookup arrays local, freeing them on each failure and normal exit. Adapted to padwave's HIDAPI allocation wrappers and heap-based lookup tables. Assisted-by: deepseek-harness:deepseek-flash
ebraminio
force-pushed
the
win-desc-alloc-fail
branch
from
December 3, 2026 09:31
e9e8cd5 to
a479fb2
Compare
MIN macro was actually raising unused macro warning so I was considering removal of it but thought can used it on the just added code. Also turn clang-cl in the comment to clang since it isn't a matter of compiler driver.
Windows back never used it, weird that it's defined.
Fail hid_open_path when the input read buffer cannot be allocated instead of returning a device that later crashes in hid_read_timeout. Treat USB/BLE device strings as optional when WCSDUP fails, so the string lookup fallbacks do not call WCSLEN on NULL. Check both CM property buffer allocations, and cast the no-CRT WCSDUP result for C++ builds. Assisted-by: deepseek-harness:deepseek-flash
This branch has not been deployed
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.
Make descriptor reconstruction and critical
hid.callocation paths fail safely.This started with two newly added allocations in the descriptor reconstructor. Once those were checked, leaving the remaining allocations unchecked would have misleadingly suggested the function was fully protected, so I extended the checks to the rest of it. I kept the diff as small as practical; some declaration moves were unavoidable to make cleanup reachable.
Key points for review:
hid_winapi_descriptor_reconstruct_pp_data()now returns-1on allocation failure and frees partial state through one null-safe cleanup path.malloctocalloc, so partially allocated tables are NULL-initialized and can be safely freed by the shared cleanup path.nextpointer if allocation fails.hid_open_path()now returnsNULLif the input read buffer cannot be allocated.WCSDUPcalls are treated as missing optional strings; USB/BLE enrichment no longer callsWCSLENon NULL.HIDAPI_STRDUPwas removed; the no-CRThid_internal_wcsdup()return type was corrected.MINmacro.Builds verified: MSVC normal C, MSVC no-CRT C, and MSVC no-CRT C++20.
I audited every
HIDAPI_MALLOC,HIDAPI_CALLOC, andHIDAPI_WCSDUPin the two Windows translation units. There is no allocation-fault injection testing, so the cleanup paths still deserve a careful review.Remaining allocation issues
These were intentionally left for maintainer input rather than folded into this PR.
Error reporting can become
"Success"after OOM.register_string_error_to_buffer()andregister_winapi_error_to_buffer()free the old buffer before duplicating/formatting the new message. If that allocation fails,hid_error()returnsL"Success"even though the operation failed. Preserving the old error helps only when one exists; a proper fix likely needs a static owned fallback or an error-status API.Device-info path conversion failure leaves a partial record.
dev->path = hid_internal_UTF16toUTF8(path);is unchecked. On failure, enumeration can return a device-info record with a NULL path, which cannot be opened. Needs a decision: drop the record or report it as partially valid.Not all device-creation handles are checked.
new_hid_device()checksinterrupt_event, but notol.hEventorwrite_ol.hEvent. These are not heap allocations, but they are the same class of failure and can leave a device object that cannot perform reads or writes.No allocation-fault injection tests.
The cleanup paths are audited and compile-tested, but not exercised under forced allocator failure. That remains the main validation gap.