mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'fix/memory_leaks_identified_by_cppcheck_v4.2' into 'release/v4.2'
Fix/memory leaks identified by cppcheck (v4.2) See merge request espressif/esp-idf!14502
This commit is contained in:
commit
6fba03f681
@ -129,6 +129,7 @@ esp_err_t esp_ds_start_sign(const void *message,
|
||||
|
||||
if (result == ETS_DS_INVALID_KEY) {
|
||||
ds_disable_release();
|
||||
free(context);
|
||||
return ESP_ERR_HW_CRYPTO_DS_INVALID_KEY;
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,7 @@ static int md5_printf(char *md, const char *fmt, ...)
|
||||
va_start(ap, fmt);
|
||||
len = vasprintf((char **)&buf, fmt, ap);
|
||||
if (buf == NULL) {
|
||||
va_end(ap);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
|
@ -162,8 +162,8 @@ int http_header_set_format(http_header_handle_t header, const char *key, const c
|
||||
char *buf = NULL;
|
||||
va_start(argptr, format);
|
||||
len = vasprintf(&buf, format, argptr);
|
||||
HTTP_MEM_CHECK(TAG, buf, return 0);
|
||||
va_end(argptr);
|
||||
HTTP_MEM_CHECK(TAG, buf, return 0);
|
||||
if (buf == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -366,9 +366,11 @@ static esp_err_t register_select(uart_select_args_t *args)
|
||||
if (args) {
|
||||
portENTER_CRITICAL(&s_registered_select_lock);
|
||||
const int new_size = s_registered_select_num + 1;
|
||||
if ((s_registered_selects = realloc(s_registered_selects, new_size * sizeof(uart_select_args_t *))) == NULL) {
|
||||
uart_select_args_t **new_selects;
|
||||
if ((new_selects = realloc(s_registered_selects, new_size * sizeof(uart_select_args_t *))) == NULL) {
|
||||
ret = ESP_ERR_NO_MEM;
|
||||
} else {
|
||||
s_registered_selects = new_selects;
|
||||
s_registered_selects[s_registered_select_num] = args;
|
||||
s_registered_select_num = new_size;
|
||||
ret = ESP_OK;
|
||||
@ -392,12 +394,9 @@ static esp_err_t unregister_select(uart_select_args_t *args)
|
||||
// last item.
|
||||
s_registered_selects[i] = s_registered_selects[new_size];
|
||||
s_registered_selects = realloc(s_registered_selects, new_size * sizeof(uart_select_args_t *));
|
||||
if (s_registered_selects || new_size == 0) {
|
||||
s_registered_select_num = new_size;
|
||||
ret = ESP_OK;
|
||||
} else {
|
||||
ret = ESP_ERR_NO_MEM;
|
||||
}
|
||||
// Shrinking a buffer with realloc is guaranteed to succeed.
|
||||
s_registered_select_num = new_size;
|
||||
ret = ESP_OK;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user