[misc] Fix possible resource leak