Fixes a use-after-free reported by Coverity.
More fixes from coverity.