add free resource defer