From 1bbdcc10d748c5ef0602300fbdac8a221da1eb82 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Fri, 22 Aug 2014 15:39:29 -0700 Subject: [PATCH] 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. --- libobs/obs-data.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libobs/obs-data.c b/libobs/obs-data.c index 69d645f8f..7419f6cc1 100644 --- a/libobs/obs-data.c +++ b/libobs/obs-data.c @@ -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) {