Pass pointer by reference and memory saving

You don't need free...