clean up allocation/setup logic for fmemopen