mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-10 13:30:05 -05:00
map: make _insert_at() fail on a removed item
You are only supposed to use _insert_new()/_remove() or _insert_at() on the map, If we detect a _insert_at() to a removed item, return an error because else we might corrupt the free list. Update unit test accordingly.
This commit is contained in:
parent
d5825b8551
commit
c07f0ccb71
2 changed files with 3 additions and 29 deletions
|
|
@ -182,20 +182,9 @@ static inline int pw_map_insert_at(struct pw_map *map, uint32_t id, void *data)
|
|||
if (item == NULL)
|
||||
return -errno;
|
||||
} else {
|
||||
if (pw_map_id_is_free(map, id)) {
|
||||
uint32_t *current = &map->free_list;
|
||||
while (*current != SPA_ID_INVALID) {
|
||||
uint32_t current_id = (*current) >> 1;
|
||||
uint32_t *next = &pw_map_get_item(map, current_id)->next;
|
||||
|
||||
if (current_id == id) {
|
||||
*current = *next;
|
||||
break;
|
||||
}
|
||||
current = next;
|
||||
}
|
||||
}
|
||||
item = pw_map_get_item(map, id);
|
||||
if (pw_map_item_is_free(item))
|
||||
return -EINVAL;
|
||||
}
|
||||
item->data = data;
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue