Fix pointer initialization and memory leak.