Skip to content

Commit

Permalink
Fix potential double free if close() only partially succeeds.
Browse files Browse the repository at this point in the history
  • Loading branch information
awused committed Jul 29, 2021
1 parent 408f3c8 commit 71f6fff
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/iterator.rs
Expand Up @@ -97,18 +97,18 @@ impl<R: Read + Seek> ArchiveIterator<R> {
/// Resources will be freed on drop if this is not called, but any errors
/// during freeing on drop will be lost.
pub fn close(self) -> Result<()> {
let mut iter = self;
iter.closed = true;
unsafe {
archive_result(
ffi::archive_read_close(self.archive_reader),
self.archive_reader,
ffi::archive_read_close(iter.archive_reader),
iter.archive_reader,
)?;
archive_result(
ffi::archive_read_free(self.archive_reader),
self.archive_reader,
ffi::archive_read_free(iter.archive_reader),
iter.archive_reader,
)?;
}
let mut iter = self;
iter.closed = true;
Ok(())
}

Expand Down

0 comments on commit 71f6fff

Please sign in to comment.