Another memory fix.

I beleave allocating on stack is a better way to reduce memory consumption.
And I figured out (I don't understand the reason, actually) that memory leaks also because of `tmp` variable.