Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/AsyncTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,12 @@ AsyncClient::~AsyncClient(){
if(_pcb) {
_close();
}
#if ASYNC_TCP_SSL_ENABLED
else
{
tcp_ssl_free_by_arg(this);
}
#endif
_free_closed_slot();
}

Expand Down
46 changes: 46 additions & 0 deletions src/tcp_mbedtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,52 @@ int tcp_ssl_free(struct tcp_pcb *tcp) {
return 0;
}

int tcp_ssl_free_by_arg(void *arg) {
TCP_SSL_DEBUG("tcp_ssl_free_by_arg(%x)\n", arg);
if(arg == NULL) {
return -1;
}
tcp_ssl_t * item = tcp_ssl_array;
if (item) {
if(item->arg == arg){
TCP_SSL_DEBUG("tcp_ssl_free_by_arg arg found at first place\n");
tcp_ssl_array = tcp_ssl_array->next;
if(item->tcp_pbuf != NULL) {
pbuf_free(item->tcp_pbuf);
}
mbedtls_ssl_free(&item->ssl_ctx);
mbedtls_ssl_config_free(&item->ssl_conf);
mbedtls_ctr_drbg_free(&item->drbg_ctx);
mbedtls_entropy_free(&item->entropy_ctx);
free(item);
return 0;
}

while(item->next && item->next->arg != arg)
item = item->next;

if(item->next == NULL){
TCP_SSL_DEBUG("tcp_ssl_free_by_arg arg not found\n");
return ERR_TCP_SSL_INVALID_CLIENTFD_DATA;//item not found
}
tcp_ssl_t * i = item->next;
item->next = i->next;
if(i->tcp_pbuf != NULL){
pbuf_free(i->tcp_pbuf);
}
mbedtls_ssl_free(&i->ssl_ctx);
mbedtls_ssl_config_free(&i->ssl_conf);
mbedtls_ctr_drbg_free(&i->drbg_ctx);
mbedtls_entropy_free(&i->entropy_ctx);
free(i);

return 0;
} else {
TCP_SSL_DEBUG("tcp_ssl_free_by_arg array empty\n");
return 0;
}
}

bool tcp_ssl_has(struct tcp_pcb *tcp) {
return tcp_ssl_get(tcp) != NULL;
}
Expand Down
1 change: 1 addition & 0 deletions src/tcp_mbedtls.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ int tcp_ssl_write(struct tcp_pcb *tcp, uint8_t *data, size_t len);
int tcp_ssl_read(struct tcp_pcb *tcp, struct pbuf *p);
int tcp_ssl_handshake_step(struct tcp_pcb *tcp);
int tcp_ssl_free(struct tcp_pcb *tcp);
int tcp_ssl_free_by_arg(void * arg);
bool tcp_ssl_has(struct tcp_pcb *tcp);
void tcp_ssl_arg(struct tcp_pcb *tcp, void * arg);
void tcp_ssl_data(struct tcp_pcb *tcp, tcp_ssl_data_cb_t arg);
Expand Down