esp_partition: Fixed use-after-free issue (coverity)

This commit is contained in:
Martin Vychodil 2023-03-05 19:32:36 +01:00 committed by BOT
parent cd747165df
commit a2b4b27b62

View File

@ -9,20 +9,18 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <sys/lock.h> #include <sys/lock.h>
#include <sys/queue.h>
#include "sdkconfig.h" #include "sdkconfig.h"
#include "esp_flash_partitions.h" #include "esp_flash_partitions.h"
#include "esp_attr.h" #include "esp_attr.h"
#include "esp_partition.h" #include "esp_partition.h"
#if !CONFIG_IDF_TARGET_LINUX #if !CONFIG_IDF_TARGET_LINUX
#include "esp_flash.h" #include "esp_flash.h"
#include "esp_flash_encrypt.h" #include "esp_flash_encrypt.h"
#endif #endif
#include "esp_log.h" #include "esp_log.h"
#include "esp_rom_md5.h" #include "esp_rom_md5.h"
#include "bootloader_util.h" #include "bootloader_util.h"
#if CONFIG_IDF_TARGET_LINUX #if CONFIG_IDF_TARGET_LINUX
#if __has_include(<bsd/string.h>) #if __has_include(<bsd/string.h>)
#include <bsd/string.h> #include <bsd/string.h>
@ -228,8 +226,8 @@ static esp_err_t load_partitions(void)
void unload_partitions(void) void unload_partitions(void)
{ {
_lock_acquire(&s_partition_list_lock); _lock_acquire(&s_partition_list_lock);
partition_list_item_t *it; partition_list_item_t *it, *tmp;
SLIST_FOREACH(it, &s_partition_list, next) { SLIST_FOREACH_SAFE(it, &s_partition_list, next, tmp) {
SLIST_REMOVE(&s_partition_list, it, partition_list_item_, next); SLIST_REMOVE(&s_partition_list, it, partition_list_item_, next);
free(it); free(it);
} }