+ if (FAILED(hr)) + { + IStream_Release(stream); + IWICComponentFactory_Release(factory); + return; + } The rest of the function is already has code to handle failure, so returning early is unnecessary.