Stop a resource leak

Stops a resource leak in the event that the system cannot malloc
Initialize the string before replacing characters