aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-11-16 15:04:23 -0800
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-12-16 19:18:51 -0800
commit8f35f16c7ed97c50ee188f13ab9d5ea1008341ae (patch)
tree1a69035b9d1a85c921a94903fb7c3f655149d17f
parente08710e373f81341844f35d0e510cb10ab764ee6 (diff)
downloadbun-8f35f16c7ed97c50ee188f13ab9d5ea1008341ae.tar.gz
bun-8f35f16c7ed97c50ee188f13ab9d5ea1008341ae.tar.zst
bun-8f35f16c7ed97c50ee188f13ab9d5ea1008341ae.zip
[libarchive] Fix occasional segfault
-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;