Fix resource leak

Fixed possible resource leak.