This looks better, but I still think you should use WICPersistOptionNoCacheStream. Some of your failure cases in create_metadata_reader will return a reference to an IWICMetadataReader, which seems wrong.