diff --git a/mongoose.c b/mongoose.c
index 7c40cb9c067655e48f5e0e234669c341b592db4b..928f11075ba27037972d650ede2a99cabf698c24 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -14203,6 +14203,7 @@ static err_t mg_lwip_tcp_sent_cb(void *arg, struct tcp_pcb *tpcb,
                                  u16_t num_sent) {
   struct mg_connection *nc = (struct mg_connection *) arg;
   DBG(("%p %p %u", nc, tpcb, num_sent));
+  if (nc == NULL) return ERR_OK;
   if ((nc->flags & MG_F_SEND_AND_CLOSE) && !(nc->flags & MG_F_WANT_WRITE) &&
       nc->send_mbuf.len == 0 && tpcb->unacked == 0) {
     mg_lwip_post_signal(MG_SIG_CLOSE_CONN, nc);