Skip to content

Commit

Permalink
fix(mbedtls): Fix memory leak
Browse files Browse the repository at this point in the history
Avoid crashes because multiple TCP connections come in simultaneously

tw16346

internal gitlab: b3fc5ca8
  • Loading branch information
wujiangang committed Nov 28, 2017
1 parent 8ea75e7 commit a1fa90a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ phy:
gitlab:
driver : 68fc7b06
lwip : eec8e741
mbedtls : 8e8090b6
mbedtls : 446df5a9
Binary file modified lib/libmbedtls.a
Binary file not shown.
14 changes: 14 additions & 0 deletions third_party/mbedtls/app/lwIPSocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,20 @@ static err_t do_accepted(void *arg, struct tcp_pcb *newpcb, err_t err)
lwIP_netconn *newconn = NULL;
lwIP_netconn *conn = arg;
err = ERR_OK;

//Avoid two TCP connections coming in simultaneously
struct tcp_pcb *pactive_pcb;
int active_pcb_num=0;
for(pactive_pcb = tcp_active_pcbs; pactive_pcb != NULL; pactive_pcb = pactive_pcb->next){
if (pactive_pcb->state == ESTABLISHED ||pactive_pcb->state == SYN_RCVD){
active_pcb_num++;
if (active_pcb_num > MEMP_NUM_TCP_PCB){
ESP_LOG("%s %d active_pcb_number:%d\n",__FILE__, __LINE__,active_pcb_num);
return ERR_MEM;
}
}
}

lwIP_REQUIRE_ACTION(conn, exit, err = ESP_ARG);
/* We have to set the callback here even though
* the new socket is unknown. conn->socket is marked as -1. */
Expand Down

0 comments on commit a1fa90a

Please sign in to comment.