Skip to content

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

Merged
robbiehanson merged 1 commit into
yapstudios:masterfrom
fabiankr:reachability
Jul 18, 2017
Merged

Make -initWithReachabilityRef: retain the ref argument, fixing a Clang analyzer warning.#414
robbiehanson merged 1 commit into
yapstudios:masterfrom
fabiankr:reachability

Conversation

@fabiankr
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

2 participants