Merge pull request #15295 from hifoolno/bug5

lwiperf: fix double-free of pcb on error
pull/15306/head
Martin Kojtal 2022-06-23 16:04:29 +01:00 committed by GitHub
commit 10e01514c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -263,7 +263,7 @@ lwiperf_tcp_close(lwiperf_state_tcp_t *conn, enum lwiperf_report_type report_typ
/* don't want to wait for free memory here... */ /* don't want to wait for free memory here... */
tcp_abort(conn->conn_pcb); tcp_abort(conn->conn_pcb);
} }
} else { } else if (conn->server_pcb != NULL) {
/* no conn pcb, this is the listener pcb */ /* no conn pcb, this is the listener pcb */
err = tcp_close(conn->server_pcb); err = tcp_close(conn->server_pcb);
LWIP_ASSERT("error", err == ERR_OK); LWIP_ASSERT("error", err == ERR_OK);
@ -565,6 +565,11 @@ lwiperf_tcp_err(void *arg, err_t err)
{ {
lwiperf_state_tcp_t *conn = (lwiperf_state_tcp_t *)arg; lwiperf_state_tcp_t *conn = (lwiperf_state_tcp_t *)arg;
LWIP_UNUSED_ARG(err); LWIP_UNUSED_ARG(err);
/* pcb is already deallocated, prevent double-free */
conn->conn_pcb = NULL;
conn->server_pcb = NULL;
lwiperf_tcp_close(conn, LWIPERF_TCP_ABORTED_REMOTE); lwiperf_tcp_close(conn, LWIPERF_TCP_ABORTED_REMOTE);
} }