I am trying to add a bunch of WCHARs to a buffer. This function is what adds it to my buffer..
DWORD add_to_buffer(BYTE *databuffer, WCHAR *path, WCHAR *value_name, DWORD type, BYTE *data, DWORD data_size, DWORD already_added) {
DWORD path_size = wcslen(path) * 2;
DWORD value_name_size = wcslen(value_name) * 2;
WCHAR *type_name = reg_type_to_wchar(type);
DWORD type_size = wcslen(type_name) * 2;
DWORD total_length = already_added + path_size + value_name_size + type_size + data_size;
*databuffer = realloc(databuffer, total_length);
CopyMemory(databuffer, path, path_size);
CopyMemory(databuffer + path_size, value_name, value_name_size);
CopyMemory(databuffer + path_size + value_name_size, type_name, type_size);
CopyMemory(databuffer + path_size + value_name_size + type_size, data, data_size);
return total_length;
}
On the second call to the add_to_buffer() the realloc() fails. I am basically calling this function over and over, while adding information to it and making it bigger as needed. I am not sure how to troubleshoot this issue as everything in VS looks correct when going into the function. databuffer is not getting freed anywhere outside of this function.