Earlier quoted context omitted.
Early returns here will require duplicated free() calls, which makes it hard to prevent leaks. This coding style is standard practice for Win32 API development.
The more typical coding style for raw Win32 is to have a block of CloseHandle/Free/... block at the end of the function, and goto it for early exit. Usually with some helper macros to easily write "if it failed, goto cleanup" one-liners.
HRESULT hr;
hr = DoFoo();
if (!SUCCESS(hr))
{
goto exit;
}
hr = DoBar();
if (!(SUCCESS(hr))
{
goto cleanup_foo;
}
hr = DoBar();
if (!(SUCCESS(hr))
{
goto cleanup_bar;
}
hr = DoBaz();
if (SUCCESS(hr))
{
CleanupBaz();
}
cleanup_bar:
CleaupBar();
cleanup_foo:
CleanupFoo();
exit:
return hr;