avio: Add an internal utility function for freeing dynamic buffers