This malloc is ugly.  It would be nice if we could stack allocate the "average" buffer on this platform and avoid the malloc/free for common cases.  But that may just turn into wasted stack space if we guess wrong.