fix memory leakage

I think returning a pointer to a block of memory allocated from heap, will result in a memory leakage.