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

Make -initWithReachabilityRef: retain the ref argument, fixing a Clang analyzer warning. #414

Merged
merged 1 commit into from Jul 18, 2017

Conversation

fabiankr
Copy link
Contributor

Without this Clang shows an analyzer warning that after calling -initWithReachabilityRef: the ref should be released. Because -initWithReachabilityRef: doesn’t retain the argument, this would result in a dangling pointer.

Warning: This change fixes the issue in YapDatabase internally, but it introduces a memory leak for consumers that are currently using -initWithReachabilityRef without releasing the ref.

analyzer

Without this Clang shows an analyzer warning that after calling -initWithReachabilityRef: the ref should be released. Because -initWithReachabilityRef: doesn’t retain the argument, this would result in a dangling pointer.

Warning: This change fixes the issue in YapDatabase internally, but it introduces a memory leak for consumers that are currently using -initWithReachabilityRef without releasing the ref.
@fabiankr
Copy link
Contributor Author

I'm not 100% sure that this should be merged. It is definitely the correct way to do it (in my opinion at least), but it will introduce a memory leak for consumers of the framework who are currently using -initWithReachabilityRef: and ignore the analyzer warning.

On the other side it fixes a crash when someone actually "fixes" the analyzer warning in the consumer code by releasing the ref after passing it to the initializer.

Ultimately, I don't think -initWithReachabilityRef: is used a lot directly, anyway. And when the convenience methods of YapReachability are used nothing changes (other than two warnings less).

@robbiehanson
Copy link
Contributor

I'm inclined to agree with the changes made. Besides, if I have to choose between a memory leak and a crash, I'd have to go with the memory leak.

@robbiehanson robbiehanson merged commit 05bba70 into yapstudios:master Jul 18, 2017
@fabiankr fabiankr deleted the reachability branch July 19, 2017 18:02
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