-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 SA xcode 7 pointed out #118
Open
jcarroll3
wants to merge
1
commit into
tonymillion:master
Choose a base branch
from
jcarroll3:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
matches CFRelease(self.reachabilityRef); in dealloc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except there's still a potential leak according to the analyzer, since
SCNetworkReachabilityCreateWithName
has already increased the retain count.While I agree that this line is necessary to match the
CFRelease
call in dealloc, the ref should also be released in the factory methods to match the create calls.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just re-ran the SA on my branch. No SA errors visible. Running xCode 7.2
Line 98 & 111 each create a ref locally, therefore I would say and hopefully everyone agrees it should be released locally. (My fix)
Ignoring all other retain / release we have sufficiently balanced the life cycle, we have 1 retain count added and one retain count removed. We have a well balanced life cycle in local scope.
Now looking at the actual instance of Reachability, it also has a stake in the lifecycle of the ref. Because it has a release in dealloc on the ref, it should keep that balance and have a retain on the ref in the init. Which is what I did.
In summary, functionality wise nothing changes. Under current impl, theres not a leak, just the SA being grumpy. So all I did was remove a retain count in the class methods, so the SA would be happy, however since I did that I created a zombie so I had to rebalance and shove a retain down the common method (the init).
Again, this is purely a commit to make the SA go away. No memory leaks introduced, and no memory leaks fixed because there are none :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The analyzer is correct. Consider the case where the
SCNetworkReachabilityRef
is created, and theinitWithReachabilityRef:
call fails. The ref will leak.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, so my implementation fixes that. Unless I'm missing something.
Line 98,
SCNetworkReachabilityRef
is created, retain count 1.Line 101, init does something with it. Sucess or fail, doesn't matter. As far as we know, the retain count is still 1. So ...
Line 103, we release it. If other objects are claiming ownership its one them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My mistake. I missed the last
CFRetain
call on line 159 because of the way the inline comments split up the diff.