return before freeing memory fix