ReturnLastError(HANDLE pipe, LPCWSTR func)
{
    ReturnError(pipe, GetLastError(), func, 1, &exit_event);
}

The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.