tcp_transport: Fix some memory leak issues by coverity static analyzer.

This commit is contained in:
aditi_lonkar 2021-03-23 11:09:21 +05:30
parent 4407c9eb83
commit 98d19efe6f
3 changed files with 10 additions and 2 deletions

View File

@ -303,7 +303,10 @@ esp_transport_handle_t esp_transport_ssl_init(void)
{
esp_transport_handle_t t = esp_transport_init();
transport_ssl_t *ssl = calloc(1, sizeof(transport_ssl_t));
ESP_TRANSPORT_MEM_CHECK(TAG, ssl, return NULL);
ESP_TRANSPORT_MEM_CHECK(TAG, ssl, {
esp_transport_destroy(t);
return NULL;
});
esp_transport_set_context_data(t, ssl);
esp_transport_set_func(t, ssl_connect, ssl_read, ssl_write, ssl_close, ssl_poll_read, ssl_poll_write, ssl_destroy);
esp_transport_set_async_connect_func(t, ssl_connect_async);

View File

@ -280,7 +280,10 @@ esp_transport_handle_t esp_transport_tcp_init(void)
{
esp_transport_handle_t t = esp_transport_init();
transport_tcp_t *tcp = calloc(1, sizeof(transport_tcp_t));
ESP_TRANSPORT_MEM_CHECK(TAG, tcp, return NULL);
ESP_TRANSPORT_MEM_CHECK(TAG, tcp, {
esp_transport_destroy(t);
return NULL;
});
tcp->sock = -1;
esp_transport_set_func(t, tcp_connect, tcp_read, tcp_write, tcp_close, tcp_poll_read, tcp_poll_write, tcp_destroy);
esp_transport_set_context_data(t, tcp);

View File

@ -459,12 +459,14 @@ esp_transport_handle_t esp_transport_ws_init(esp_transport_handle_t parent_handl
ws->path = strdup("/");
ESP_TRANSPORT_MEM_CHECK(TAG, ws->path, {
free(ws);
esp_transport_destroy(t);
return NULL;
});
ws->buffer = malloc(DEFAULT_WS_BUFFER);
ESP_TRANSPORT_MEM_CHECK(TAG, ws->buffer, {
free(ws->path);
free(ws);
esp_transport_destroy(t);
return NULL;
});