[fix] Extractor falls out of scope
All checks were successful
continuous-integration/drone/push Build is passing

Extractor was created and destroyed within the if scope, leading to
a dereference error when trying to call the virtual writer methods.
This commit is contained in:
Armin Friedl 2020-02-23 09:56:33 +01:00
parent 86ab4a5050
commit 064c936f11
Signed by: armin
GPG key ID: 48C726EEE7FBCBC8
3 changed files with 12 additions and 8 deletions

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
.clangd/ .clangd/
build/ build/
target/
compile_commands.json compile_commands.json
# Created by https://www.gitignore.io/api/vim,c++,emacs,ninja # Created by https://www.gitignore.io/api/vim,c++,emacs,ninja

View file

@ -106,17 +106,17 @@ ArchiveSpec Archive::check() {
void Archive::extract(ExtractSpec extract_spec) { void Archive::extract(ExtractSpec extract_spec) {
std::filesystem::path abs_path = std::filesystem::absolute(this->path); std::filesystem::path abs_path = std::filesystem::absolute(this->path);
std::unique_ptr<ArchiveExtractorSys> extractor;
if(extract_spec.make_dir) { if(extract_spec.make_dir) {
ArchiveExtractorSys extractor{ArchiveExtractorSys{extract_spec.dirname}};
logger::trace("Creating extract directory {}", extract_spec.dirname.string()); logger::trace("Creating extract directory {}", extract_spec.dirname.string());
ArchiveReaderSys reader{abs_path}; extractor = std::unique_ptr<ArchiveExtractorSys>(new ArchiveExtractorSys{extract_spec.dirname});
extractor.extract_all(reader);
} else { } else {
ArchiveExtractorSys extractor{}; extractor = std::unique_ptr<ArchiveExtractorSys>(new ArchiveExtractorSys{});
logger::trace("Creating extract directory {}", extract_spec.dirname.string());
ArchiveReaderSys reader{abs_path};
extractor.extract_all(reader);
} }
ArchiveReaderSys reader{abs_path};
extractor->extract_all(reader);
} }
} // namespace xwim } // namespace xwim

View file

@ -79,6 +79,8 @@ xwim::ArchiveExtractorSys::ArchiveExtractorSys(std::filesystem::path& root) {
this->writer = archive_write_disk_new(); this->writer = archive_write_disk_new();
archive_write_disk_set_standard_lookup(this->writer); archive_write_disk_set_standard_lookup(this->writer);
logger::trace("Constructed ArchiveExtractorSys at {:p}", (void*) this->writer);
} }
xwim::ArchiveExtractorSys::ArchiveExtractorSys() { xwim::ArchiveExtractorSys::ArchiveExtractorSys() {
@ -86,6 +88,7 @@ xwim::ArchiveExtractorSys::ArchiveExtractorSys() {
this->writer = archive_write_disk_new(); this->writer = archive_write_disk_new();
archive_write_disk_set_standard_lookup(this->writer); archive_write_disk_set_standard_lookup(this->writer);
logger::trace("Constructed ArchiveExtractorSys at {:p}", (void*) this->writer);
} }
void xwim::ArchiveExtractorSys::extract_all(xwim::ArchiveReaderSys& reader) { void xwim::ArchiveExtractorSys::extract_all(xwim::ArchiveReaderSys& reader) {
@ -111,7 +114,7 @@ void xwim::ArchiveExtractorSys::extract_entry(xwim::ArchiveReaderSys& reader) {
} }
xwim::ArchiveExtractorSys::~ArchiveExtractorSys(){ xwim::ArchiveExtractorSys::~ArchiveExtractorSys(){
logger::trace("Destructing ArchiveExtractorSys"); logger::trace("Destructing ArchiveExtractorSys at {:p}", (void*) this->writer);
if(this->writer) { if(this->writer) {
archive_write_close(this->writer); archive_write_close(this->writer);
archive_write_free(this->writer); archive_write_free(this->writer);