Merge branch 'bugfix/wpa_supplicant_coverity_issue_fixes_v4.1' into 'release/v4.1'

Fix some issues raised by Coverity static Analyzer.(backport_v4.1)

See merge request espressif/esp-idf!11920
This commit is contained in:
Jiang Jiang Jian
2021-03-23 03:27:44 +00:00
11 changed files with 28 additions and 7 deletions

View File

@ -97,6 +97,7 @@ static esp_err_t http_header_new_item(http_header_handle_t header, const char *k
_header_new_item_exit:
free(item->key);
free(item->value);
free(item);
return ESP_ERR_NO_MEM;
}

View File

@ -166,6 +166,7 @@ static esp_err_t cmd_set_prop_vals_handler(LocalCtrlMessage *req,
ESP_LOGE(TAG, "Failed to allocate memory for setting values");
free(idxs);
free(vals);
free(resp_payload);
return ESP_ERR_NO_MEM;
}
for (size_t i = 0; i < req->cmd_set_prop_vals->n_props; i++) {

View File

@ -76,6 +76,7 @@ esp_err_t esp_netif_add_to_list(esp_netif_t *netif)
item->netif = netif;
if ((ret = esp_netif_list_lock()) != ESP_OK) {
free(item);
return ret;
}
@ -185,4 +186,4 @@ esp_netif_t *esp_netif_get_handle_from_ifkey(const char *if_key)
} while (NULL != (esp_netif = esp_netif_next_unsafe(esp_netif)));
esp_netif_list_unlock();
return NULL;
}
}

View File

@ -5586,7 +5586,12 @@ FRESULT f_mkfs (
sz_buf = len / ss; /* Size of working buffer (sector) */
szb_buf = sz_buf * ss; /* Size of working buffer (byte) */
}
if (!buf || sz_buf == 0) return FR_NOT_ENOUGH_CORE;
if (!buf || sz_buf == 0) {
if(buf != NULL) {
ff_memfree(buf);
}
return FR_NOT_ENOUGH_CORE;
}
/* Determine where the volume to be located (b_vol, sz_vol) */
if (FF_MULTI_PARTITION && part != 0) {

View File

@ -628,12 +628,12 @@ static int vfs_fat_link(void* ctx, const char* n1, const char* n2)
}
fail3:
f_close(pf2);
free(pf2);
fail2:
f_close(pf1);
free(pf1);
fail1:
free(buf);
free(pf2);
free(pf1);
if (res != FR_OK) {
ESP_LOGD(TAG, "%s: fresult=%d", __func__, res);
errno = fresult_to_errno(res);

View File

@ -286,7 +286,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

@ -184,7 +184,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;
});

View File

@ -82,6 +82,7 @@ static esp_err_t cmd_get_status_handler(WiFiConfigPayload *req,
WifiConnectedState *connected = (WifiConnectedState *)(
malloc(sizeof(WifiConnectedState)));
if (!connected) {
free(resp_payload);
ESP_LOGE(TAG, "Error allocating memory");
return ESP_ERR_NO_MEM;
}

View File

@ -675,7 +675,7 @@ static int sae_derive_commit_element_ffc(struct sae_data *sae,
static int sae_derive_commit(struct sae_data *sae)
{
struct crypto_bignum *mask;
struct crypto_bignum *mask = NULL;
int ret = -1;
unsigned int counter = 0;
@ -690,6 +690,9 @@ static int sae_derive_commit(struct sae_data *sae)
*/
return ESP_FAIL;
}
if(mask) {
crypto_bignum_deinit(mask, 1);
}
mask = sae_get_rand_and_mask(sae);
if (mask == NULL) {

View File

@ -749,6 +749,7 @@ static int eap_peer_sm_init(void)
s_wpa2_data_lock = xSemaphoreCreateRecursiveMutex();
if (!s_wpa2_data_lock) {
free(sm);
wpa_printf(MSG_ERROR, "wpa2 eap_peer_sm_init: failed to alloc data lock");
return ESP_ERR_NO_MEM;
}