Skip to content

Commit 86b0252

Browse files
committed
fixed NetTcp.cc baremetal bug where a segfault on double delete was happening when user closes a connection twice.
1 parent f32cd8a commit 86b0252

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/native/NetTcp.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ void ebbrt::NetworkManager::TcpEntry::Destroy() {
363363
std::lock_guard<ebbrt::SpinLock> guard(network_manager->tcp_write_lock_);
364364
network_manager->tcp_pcbs_.erase(*this);
365365
}
366+
kassert(this);
366367
event_manager->DoRcu([this]() { delete this; });
367368
}
368369

@@ -719,6 +720,9 @@ bool ebbrt::NetworkManager::TcpEntry::Receive(
719720
// Second check the RST bit
720721
if (unlikely(flags & kTcpRst)) {
721722
state = kClosed;
723+
#ifdef __EBBRT_ENABLE_BAREMETAL_NIC__
724+
bool flag = false;
725+
#endif
722726
if (state == kSynReceived) {
723727
// RFC 793 Page 70:
724728
// "If this connection was initiated with a passive OPEN (i.e., came
@@ -729,7 +733,6 @@ bool ebbrt::NetworkManager::TcpEntry::Receive(
729733
// In either case, all segments on the retransmission queue should be
730734
// removed. And in the active OPEN case, enter the CLOSED state and
731735
// delete the TCB, and return."
732-
733736
handler->Abort();
734737
} else if (state >= kEstablished && state <= kCloseWait) {
735738
// If the RST bit is set then, any outstanding RECEIVEs and SEND
@@ -745,10 +748,17 @@ bool ebbrt::NetworkManager::TcpEntry::Receive(
745748
// RFC 793 Page 70:
746749
// If the RST bit is set then, enter the CLOSED state, delete the TCB,
747750
// and return.
751+
#ifdef __EBBRT_ENABLE_BAREMETAL_NIC__
752+
flag = true;
753+
#endif
748754
}
749755
Purge();
750756
DisableTimers();
751-
Destroy();
757+
#ifdef __EBBRT_ENABLE_BAREMETAL_NIC__
758+
if (flag == false) Destroy();
759+
#else
760+
Destroy();
761+
#endif
752762
return false;
753763
} else if (unlikely(flags & kTcpSyn)) {
754764
// RFC 793 Page 71:

0 commit comments

Comments
 (0)