Manual malloc/free calls to make sure buffers get cleaned up