mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-06-13 10:18:30 -04:00
Fix obs_data_item_setdata
It would try to move data from the old pointer even if the pointer was changed via realloc, which would cause it to copy data from freed memory. Instead, just get the position of the data and call memmove to move it up.
This commit is contained in:
@@ -377,7 +377,8 @@ static inline void obs_data_item_setdata(
|
||||
return;
|
||||
|
||||
struct obs_data_item *item = *p_item;
|
||||
void *old_non_user_data = get_default_data_ptr(item);
|
||||
ptrdiff_t old_default_data_pos =
|
||||
(uint8_t*)get_default_data_ptr(item) - (uint8_t*)item;
|
||||
item_data_release(item);
|
||||
|
||||
item->data_size = size;
|
||||
@@ -387,8 +388,8 @@ static inline void obs_data_item_setdata(
|
||||
item = obs_data_item_ensure_capacity(item);
|
||||
|
||||
if (item->default_size || item->autoselect_size)
|
||||
move_data(*p_item, old_non_user_data, item,
|
||||
get_default_data_ptr(item),
|
||||
memmove(get_default_data_ptr(item),
|
||||
(uint8_t*)item + old_default_data_pos,
|
||||
item->default_len + item->autoselect_size);
|
||||
|
||||
if (size) {
|
||||
|
||||
Reference in New Issue
Block a user