This following code captures the this pointer by reference. When the onCommit handler is run, the class has already been destructed and the pointer's value has changed. _opCtx, _entry, and _collection should be captured by value.
_opCtx->recoveryUnit()->onCommit([&] {
// This will prevent the unfinished index from being visible on index iterators.
auto minVisible =
repl::ReplicationCoordinator::get(_opCtx)->getMinimumVisibleSnapshot(_opCtx);
_entry->setMinimumVisibleSnapshot(minVisible);
_collection->setMinimumVisibleSnapshot(minVisible);
});