From b0212b81620f8c43d691e5d50d2c4f180a20d8c9 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Sun, 30 Jan 2022 21:03:32 +0100 Subject: [PATCH] Fixed the memory bug! thanks spy --- src/package.v | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/package.v b/src/package.v index 91e8db3..a4d1d6c 100644 --- a/src/package.v +++ b/src/package.v @@ -125,7 +125,6 @@ pub fn read_pkg(pkg_path string) ?Pkg { C.archive_read_free(a) } - mut buf := voidptr(0) mut files := []string{} mut pkg_info := PkgInfo{} @@ -143,7 +142,7 @@ pub fn read_pkg(pkg_path string) ?Pkg { size := C.archive_entry_size(entry) // TODO can this unsafe block be avoided? - buf = unsafe { malloc(size) } + buf := unsafe { malloc(size) } defer { unsafe { free(buf) @@ -151,7 +150,8 @@ pub fn read_pkg(pkg_path string) ?Pkg { } C.archive_read_data(a, buf, size) - pkg_text := unsafe { cstring_to_vstring(buf) } + pkg_text := unsafe { buf.vstring_with_len(size).clone() } + pkg_info = parse_pkg_info_string(pkg_text) ? } else { C.archive_read_data_skip(a)