On Thu, Nov 7, 2019 at 10:19 PM Paul Gofman <gofmanp(a)gmail.com> wrote:
+static HRESULT set_string(char **param_data, const char *string) +{ + HeapFree(GetProcessHeap(), 0, *param_data); + *param_data = HeapAlloc(GetProcessHeap(), 0, strlen(string) + 1); + if (!*param_data) + { + ERR("Out of memory.\n"); + return E_OUTOFMEMORY; + } + strcpy(*param_data, string); + return D3D_OK; +}
I know that this is not new code but I have a couple of comments. Another option here would be to only free the old memory after the new allocation succeeds. I guess it's not particularly important since the situation must be pretty hopeless if allocating a string fails. Regardless, you should probably make use of the helpers from heap.h.