Fix resource leak, wrong null pointer check
Fix resource leak, wrong null pointer check

MacdonaldThompson/thesis,MacdonaldThompson/thesis,MacdonaldThompson/thesis,MacdonaldThompson/thesis,MacdonaldThompson/thesis