Copilot commented on code in PR #199:
URL: https://github.com/apache/avro-rs/pull/199#discussion_r2115694582
##########
avro/src/writer.rs:
##########
@@ -348,7 +354,18 @@ impl<'a, W: Write> Writer<'a, W> {
pub fn into_inner(mut self) -> AvroResult<W> {
self.maybe_write_header()?;
self.flush()?;
- Ok(self.writer)
+
+ let mut this = ManuallyDrop::new(self);
+
+ // Extract every member that is not Copy and therefore should be
dropped
+ let _resolved_schema = std::mem::take(&mut this.resolved_schema);
+ let _buffer = std::mem::take(&mut this.buffer);
+ let _user_metadata = std::mem::take(&mut this.user_metadata);
Review Comment:
The `into_inner` implementation doesn’t take `schemata`, so that field
remains in `ManuallyDrop` and leaks memory. Consider adding `let _schemata =
std::mem::take(&mut this.schemata);` before reading out the writer.
```suggestion
let _user_metadata = std::mem::take(&mut this.user_metadata);
let _schemata = std::mem::take(&mut this.schemata);
```
##########
avro/src/writer.rs:
##########
@@ -25,12 +25,18 @@ use crate::{
AvroResult, Codec, Error,
};
use serde::Serialize;
-use std::{collections::HashMap, io::Write, marker::PhantomData,
ops::RangeInclusive};
+use std::{
+ collections::HashMap, io::Write, marker::PhantomData, mem::ManuallyDrop,
ops::RangeInclusive,
+};
const DEFAULT_BLOCK_SIZE: usize = 16000;
const AVRO_OBJECT_HEADER: &[u8] = b"Obj\x01";
/// Main interface for writing Avro formatted values.
+///
+/// It is critical to call flush before `Writer<W>` is dropped. Though
dropping will attempt to flush
Review Comment:
Update this comment: since `Writer` now auto-flushes in its `Drop` impl
(ignoring errors), calling `flush` before drop is no longer strictly required
for data integrity.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]