Add memory allocation

Now can use strcat() correctly. It's more safe than before.
Also can get out of the receive loop when receive "\n" or "\r" or "\r\n".