mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-02 20:24:32 +02:00
Merge branch 'fix/heap-trace-hash-map-remove_v5.2' into 'release/v5.2'
fix(heap): prevent double traversal of hashmap in map_find_and_remove (backport v5.2) See merge request espressif/esp-idf!28062
This commit is contained in:
@@ -134,12 +134,18 @@ static HEAP_IRAM_ATTR heap_trace_record_t* map_find_and_remove(void *p)
|
|||||||
{
|
{
|
||||||
size_t idx = hash_idx(p);
|
size_t idx = hash_idx(p);
|
||||||
heap_trace_record_t *r_cur = NULL;
|
heap_trace_record_t *r_cur = NULL;
|
||||||
|
heap_trace_record_t *r_prev = NULL;
|
||||||
SLIST_FOREACH(r_cur, &hash_map[idx], slist_hashmap) {
|
SLIST_FOREACH(r_cur, &hash_map[idx], slist_hashmap) {
|
||||||
if (r_cur->address == p) {
|
if (r_cur->address == p) {
|
||||||
total_hashmap_hits++;
|
total_hashmap_hits++;
|
||||||
SLIST_REMOVE(&hash_map[idx], r_cur, heap_trace_record_t, slist_hashmap);
|
if (r_prev) {
|
||||||
|
SLIST_REMOVE_AFTER(r_prev, slist_hashmap);
|
||||||
|
} else {
|
||||||
|
SLIST_REMOVE_HEAD(&hash_map[idx], slist_hashmap);
|
||||||
|
}
|
||||||
return r_cur;
|
return r_cur;
|
||||||
}
|
}
|
||||||
|
r_prev = r_cur;
|
||||||
}
|
}
|
||||||
total_hashmap_miss++;
|
total_hashmap_miss++;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Reference in New Issue
Block a user