Another memory fix.

I believe allocating on stack is a better way to free the memory. Because this is more safe. And there is no reason to use malloc here.

And I am not sure, but I guess that memory leaks also because of `tmp` variable.