jni fix potential crash when freeing image paths before closing the image