Skip to content

Commit

Permalink
Plug two memory leaks when handling entry pathname/hardlink
Browse files Browse the repository at this point in the history
We avoid now calling `.into_raw()` so we don't need to read the raw
pointer back, to free it.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
  • Loading branch information
otavio committed Sep 14, 2020
1 parent 2caedb8 commit 058b781
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,24 +208,26 @@ where
match ffi::archive_read_next_header(archive_reader, &mut entry) {
ffi::ARCHIVE_EOF => return Ok(()),
ffi::ARCHIVE_OK => {
let target_path =
dest.join(CStr::from_ptr(ffi::archive_entry_pathname(entry)).to_str()?);
ffi::archive_entry_set_pathname(
entry,
CString::new(target_path.to_str().unwrap())
.unwrap()
.into_raw(),
);
let target_path = {
let p = dest
.join(CStr::from_ptr(ffi::archive_entry_pathname(entry)).to_str()?);
let p = p.to_str().unwrap();

CString::new(p).unwrap()
};

ffi::archive_entry_set_pathname(entry, target_path.as_ptr());

let link_name = ffi::archive_entry_hardlink(entry);
if !link_name.is_null() {
let target_path = dest.join(CStr::from_ptr(link_name).to_str()?);
ffi::archive_entry_set_hardlink(
entry,
CString::new(target_path.to_str().unwrap())
.unwrap()
.into_raw(),
);
let target_path = {
let p = dest.join(CStr::from_ptr(link_name).to_str()?);
let p = p.to_str().unwrap();

CString::new(p).unwrap()
};

ffi::archive_entry_set_hardlink(entry, target_path.as_ptr());
}

ffi::archive_write_header(archive_writer, entry);
Expand Down

0 comments on commit 058b781

Please sign in to comment.