Merge "Avoid attempting to free invalid buffers" into main