houz is right. i don't think you should release the read lock before you're done with img. that should probably move right before each return point of this function? or just grab whatever you need now and copy locally, then release the struct (i.e. copy width/height, filename to something on the stack)