Properly allocating the buffer with clearing out the memory to fix Valgrind errors.