Fix resource leak under an error condition.