Fix pointer indirection and memory leak