Skip to content

Fix leaks in Firestore #2199

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

Merged
merged 3 commits into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Firestore/Source/Local/FSTLRUGarbageCollector.mm
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ size_t size() const {
};

@implementation FSTLRUGarbageCollector {
id<FSTLRUDelegate> _delegate;
__weak id<FSTLRUDelegate> _delegate;
LruParams _params;
}

Expand Down
3 changes: 2 additions & 1 deletion Firestore/Source/Local/FSTLevelDBMutationQueue.mm
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ - (instancetype)initWithUserID:(std::string)userID
@end

@implementation FSTLevelDBMutationQueue {
FSTLevelDB *_db;
// This instance is owned by FSTLevelDB; avoid a retain cycle.
__weak FSTLevelDB *_db;

/** The normalized userID (e.g. nil UID => @"" userID) used in our LevelDB keys. */
std::string _userID;
Expand Down
3 changes: 2 additions & 1 deletion Firestore/Source/Local/FSTLevelDBQueryCache.mm
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ @interface FSTLevelDBQueryCache ()
@end

@implementation FSTLevelDBQueryCache {
FSTLevelDB *_db;
// This instance is owned by FSTLevelDB; avoid a retain cycle.
__weak FSTLevelDB *_db;

/**
* The last received snapshot version. This is part of `metadata` but we store it separately to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ void OnReachabilityChangedCallback(SCNetworkReachabilityRef /*unused*/,
class ConnectivityMonitorApple : public ConnectivityMonitor {
public:
explicit ConnectivityMonitorApple(AsyncQueue* worker_queue)
: ConnectivityMonitor{worker_queue}, reachability_{CreateReachability()} {
: ConnectivityMonitor{worker_queue} {
reachability_ = CreateReachability();
if (!reachability_) {
LOG_DEBUG("Failed to create reachability monitor.");
return;
}

SCNetworkReachabilityFlags flags;
if (SCNetworkReachabilityGetFlags(reachability_, &flags)) {
SetInitialStatus(ToNetworkStatus(flags));
Expand Down Expand Up @@ -108,10 +114,14 @@ explicit ConnectivityMonitorApple(AsyncQueue* worker_queue)
}

~ConnectivityMonitorApple() {
bool success =
SCNetworkReachabilitySetDispatchQueue(reachability_, nullptr);
if (!success) {
LOG_DEBUG("Couldn't unset reachability queue");
if (reachability_) {
bool success =
SCNetworkReachabilitySetDispatchQueue(reachability_, nullptr);
if (!success) {
LOG_DEBUG("Couldn't unset reachability queue");
}

CFRelease(reachability_);
}
}

Expand All @@ -121,7 +131,7 @@ void OnReachabilityChanged(SCNetworkReachabilityFlags flags) {
}

private:
SCNetworkReachabilityRef reachability_;
SCNetworkReachabilityRef reachability_ = nil;
};

namespace {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class WatchStreamDelegate {
void NotifyDelegateOnClose(const util::Status& status);

private:
id<FSTWatchStreamDelegate> delegate_;
__weak id<FSTWatchStreamDelegate> delegate_;
};

/** A C++ bridge that invokes methods on an `FSTWriteStreamDelegate`. */
Expand All @@ -202,7 +202,7 @@ class WriteStreamDelegate {
void NotifyDelegateOnClose(const util::Status& status);

private:
id<FSTWriteStreamDelegate> delegate_;
__weak id<FSTWriteStreamDelegate> delegate_;
};

} // namespace bridge
Expand Down