Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix (harmless) memory leaks & replace magic number with constant #309

Merged
merged 1 commit into from
Jan 16, 2024

Conversation

eumpf0
Copy link
Contributor

@eumpf0 eumpf0 commented Jan 4, 2024

  • Add preprocessor constant DEVLIST_ALLOC_INITIAL_LEN to replace magic number 64 in allocations of device info list. The named constant expresses meaning and makes bugs & memory-leaks due to missed code changes less likely, should one decide to change the number of slots to allocate in the device info list.

  • Fix the same errorneous code in freeing the device info list at three points in the code:
    Calling fido_dev_info_free with length argument ndevs deallocates only the filled entries of the device info list, while leaving the empty entries dangling. This does not seem to leak any data, though.
    The commit fixes the code to actually deallocate the whole array.

@LDVG
Copy link
Contributor

LDVG commented Jan 4, 2024

Add preprocessor constant DEVLIST_ALLOC_INITIAL_LEN ...

Would you oppose making this slightly shorter, e.g. DEVLIST_LEN?

Calling fido_dev_info_free with length argument ndevs deallocates only the filled entries of the device info list, while leaving the empty entries dangling. This does not seem to leak any data, though. The commit fixes the code to actually deallocate the whole array.

The current usage should not leak and is how libfido2 itself calls fido_dev_info_free() in its examples and tools. libfido2 does allow passing the entire length of the list even if only a subset of it was populated by fido_dev_info_manifest() so I'm not opposed to the change if we prefer that approach.

Would you mind a) splitting your changes into two commits (one for the constant, one for the changed fido_dev_info_free() calls); b) rewording the commit messages in accordance to my comments in your other PR; and c) reword the part about erroneous freeing/memory leaks?

Thanks!

@LDVG LDVG force-pushed the pr-memory-leak-magic-constant branch from c738182 to 402a764 Compare January 16, 2024 12:37
Copy link
Contributor

@LDVG LDVG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted according to previous comment.

Add preprocessor constant `DEVLIST_LEN` to replace magic number 64 in
allocations of device info list.
@LDVG LDVG force-pushed the pr-memory-leak-magic-constant branch from 402a764 to f6f73bf Compare January 16, 2024 12:45
@LDVG LDVG merged commit f6f73bf into Yubico:main Jan 16, 2024
13 checks passed
@eumpf0 eumpf0 deleted the pr-memory-leak-magic-constant branch January 17, 2024 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants