Dmitry Timoshkov dmitry@baikal.ru wrote:
Also, I just noticed that you're calling create_metadata_reader unconditionally from QueryInterface, and not checking in the process whether the reader has already been created. That will leak if QI is called multiple times.
I'm not sure doing real work inside QueryInterface is a good idea. It's pretty surprising.
I think it would make more sense to do this when a method on IWICMetadataBlockReader is first called, or in Initialize if WICDecodeMetadataCacheOnLoad is specified (though doing it in Initialize would require creating the frame objects then as well, and probably combining their refcounts with the parent).
MSDN suggests different ways of creating a metadata reader:
- when creating a IWICBitmapFrameDecode
- when creating a block reader
- inside of GetReaderByIndex
It's all up to an implementor. I decided to that at #1. Each instance of IWICBitmapFrameDecode has its own metadata reader, I don't see how it could be created twice or leaked.
I take that back, thanks for the comments!