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

ScopedCFRef helper to manage CF objects #36

Merged
merged 3 commits into from
Jan 31, 2024
Merged

ScopedCFRef helper to manage CF objects #36

merged 3 commits into from
Jan 31, 2024

Conversation

hrantzsch
Copy link
Owner

Add a ScopedCFRef wrapper for CF objects that ensures that CFRelease is called when it leaves the scope.

@codecov
Copy link

codecov bot commented Aug 27, 2023

Codecov Report

Attention: 42 lines in your changes are missing coverage. Please review.

Comparison is base (ec80ca8) 48.51% compared to head (6708591) 50.26%.

Files Patch % Lines
src/keychain_mac.cpp 30.00% 7 Missing and 35 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #36      +/-   ##
==========================================
+ Coverage   48.51%   50.26%   +1.75%     
==========================================
  Files           3        3              
  Lines         202      187      -15     
  Branches       77       76       -1     
==========================================
- Hits           98       94       -4     
+ Misses         45       30      -15     
- Partials       59       63       +4     
Flag Coverage Δ
unittests 50.26% <30.00%> (+1.75%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hrantzsch hrantzsch requested a review from reneme August 27, 2023 14:55
Copy link
Collaborator

@reneme reneme left a comment

Choose a reason for hiding this comment

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

I mainly looked at the ScopedCFRef<>. Not so much its usage. I'm not super familiar with the Apple APIs, unfortunately. Nevertheless, one word of warning: If some API takes ownership of a CFRef you're passing in, you might want to have something like:

T release() {
    auto out = _ref;
    _ref = nullptr;
    return out;
}

Otherwise, macOS might free something internally that your ScopedCFRef<> freed already.

Particularly createQuery() could be prone to that, as it creates a CFMutableDictionaryRef that is appended with some objects that are auto-released in the same scope. The CFMutableDictionaryRef is eventually returned and therefore lives longer than its members. Maybe CFDictionaryAddValue() creates a deep copy, though, no idea. Just putting this out here.

src/keychain_mac.cpp Outdated Show resolved Hide resolved
src/keychain_mac.cpp Outdated Show resolved Hide resolved
src/keychain_mac.cpp Outdated Show resolved Hide resolved
src/keychain_mac.cpp Outdated Show resolved Hide resolved
src/keychain_mac.cpp Outdated Show resolved Hide resolved
src/keychain_mac.cpp Outdated Show resolved Hide resolved
@reneme reneme self-requested a review January 5, 2024 10:44
@hrantzsch hrantzsch merged commit 673a29b into master Jan 31, 2024
23 of 24 checks passed
@hrantzsch hrantzsch deleted the macos-raii branch January 31, 2024 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants