use malloc to allocate memory on heap instead of using local stack variable.