aboutsummaryrefslogtreecommitdiff
path: root/src/libarchive/libarchive.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/libarchive/libarchive.zig')
-rw-r--r--src/libarchive/libarchive.zig9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/libarchive/libarchive.zig b/src/libarchive/libarchive.zig
index fda447c1d..87580a423 100644
--- a/src/libarchive/libarchive.zig
+++ b/src/libarchive/libarchive.zig
@@ -266,7 +266,10 @@ pub const BufferReadStream = struct {
pub fn deinit(this: *BufferReadStream) void {
_ = lib.archive_read_close(this.archive);
- _ = lib.archive_read_free(this.archive);
+ // don't free it if we never actually read it
+ if (this.reading) {
+ _ = lib.archive_read_free(this.archive);
+ }
}
pub fn openRead(this: *BufferReadStream) c_int {
@@ -278,8 +281,6 @@ pub const BufferReadStream = struct {
// // lib.archive_read_set_switch_callback(this.archive, this.archive_s);
// _ = lib.archive_read_set_callback_data(this.archive, this);
- this.reading = true;
-
_ = lib.archive_read_support_format_tar(this.archive);
_ = lib.archive_read_support_format_gnutar(this.archive);
_ = lib.archive_read_support_filter_gzip(this.archive);
@@ -287,6 +288,8 @@ pub const BufferReadStream = struct {
const rc = lib.archive_read_open_memory(this.archive, this.buf.ptr, this.buf.len);
+ this.reading = rc > -1;
+
// _ = lib.archive_read_support_compression_all(this.archive);
return rc;