Skip to content

Commit a3f3e6d

Browse files
cynthiajianga-maurice
authored andcommitted
Fix a future warning that complains handle not get released properly.
In the FutureBase constructor, we detached the handle since already has the actual future instance to hold the reference count. PiperOrigin-RevId: 315973013
1 parent 7c1d0b7 commit a3f3e6d

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

app/src/include/firebase/internal/future_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ inline FutureBase::FutureBase(detail::FutureApiInterface* api,
204204
const FutureHandle& handle)
205205
: api_(api), handle_(handle) {
206206
api_->ReferenceFuture(handle_);
207+
// Once the FutureBase has reference, we don't need extra handle reference.
208+
handle_.Detach();
207209
detail::RegisterForCleanup(api_, this);
208210
}
209211

app/src/reference_counted_future_impl.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -701,10 +701,9 @@ bool ReferenceCountedFutureImpl::IsReferencedExternally() const {
701701
}
702702
for (int i = 0; i < last_results_.size(); i++) {
703703
if (last_results_[i].status() != kFutureStatusInvalid) {
704-
// If the status is not invalid, this entry is using up 2 references,
705-
// one for the Future and one for the FutureHandle it holds.
704+
// If the status is not invalid, this entry is using up a reference.
706705
// Count up the internal references.
707-
internal_references += 2;
706+
internal_references++;
708707
}
709708
}
710709
// If there are more references than the internal ones, someone is holding

0 commit comments

Comments
 (0)