block: qcow2: Flush the buffer explicitly when writing pointer table

Previously the code relies on the implicit flush when BufWriter is
dropped. That's not safe.

Per BufWriter's document:

```
It is critical to call flush before BufWriter<W> is dropped. Though
dropping will attempt to flush the contents of the buffer, any errors
that happen in the process of dropping will be ignored. Calling flush
ensures that the buffer is empty and thus dropping will not even attempt
file operations.
```

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu
2025-11-29 20:07:24 +00:00
committed by Rob Bradford
parent 4abebc9e56
commit 85556951a6

View File

@@ -80,6 +80,7 @@ impl QcowRawFile {
};
buffer.write_u64::<BigEndian>(val)?;
}
buffer.flush()?;
Ok(())
}