diff --git a/src/core/tcp.c b/src/core/tcp.c
index c98c43f..b019c3a 100644
--- a/src/core/tcp.c
+++ b/src/core/tcp.c
@@ -1778,7 +1778,7 @@ tcp_kill_state(enum tcp_state state)
  * Kills the oldest connection that is in TIME_WAIT state.
  * Called from tcp_alloc() if no more connections are available.
  */
-static void
+void
 tcp_kill_timewait(void)
 {
   struct tcp_pcb *pcb, *inactive;
diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c
index 428a6f4..efd4a51 100644
--- a/src/core/tcp_in.c
+++ b/src/core/tcp_in.c
@@ -997,6 +997,7 @@ tcp_process(struct tcp_pcb *pcb)
           TCP_RMV_ACTIVE(pcb);
           pcb->state = TIME_WAIT;
           TCP_REG(&tcp_tw_pcbs, pcb);
+          TCP_TW_LIMIT(MEMP_NUM_TCP_PCB_TIME_WAIT);
         } else {
           tcp_ack_now(pcb);
           pcb->state = CLOSING;
@@ -1015,6 +1016,7 @@ tcp_process(struct tcp_pcb *pcb)
         TCP_RMV_ACTIVE(pcb);
         pcb->state = TIME_WAIT;
         TCP_REG(&tcp_tw_pcbs, pcb);
+        TCP_TW_LIMIT(MEMP_NUM_TCP_PCB_TIME_WAIT);
       }
       break;
     case CLOSING:
@@ -1025,6 +1027,7 @@ tcp_process(struct tcp_pcb *pcb)
         TCP_RMV_ACTIVE(pcb);
         pcb->state = TIME_WAIT;
         TCP_REG(&tcp_tw_pcbs, pcb);
+        TCP_TW_LIMIT(MEMP_NUM_TCP_PCB_TIME_WAIT);
       }
       break;
     case LAST_ACK:
