Fixed the memory bug! thanks spy

main
Jef Roosens 2022-01-30 21:03:32 +01:00
parent 766e097be8
commit b0212b8162
Signed by untrusted user: Jef Roosens
GPG Key ID: B580B976584B5F30
1 changed files with 3 additions and 3 deletions

View File

@ -125,7 +125,6 @@ pub fn read_pkg(pkg_path string) ?Pkg {
C.archive_read_free(a) C.archive_read_free(a)
} }
mut buf := voidptr(0)
mut files := []string{} mut files := []string{}
mut pkg_info := PkgInfo{} mut pkg_info := PkgInfo{}
@ -143,7 +142,7 @@ pub fn read_pkg(pkg_path string) ?Pkg {
size := C.archive_entry_size(entry) size := C.archive_entry_size(entry)
// TODO can this unsafe block be avoided? // TODO can this unsafe block be avoided?
buf = unsafe { malloc(size) } buf := unsafe { malloc(size) }
defer { defer {
unsafe { unsafe {
free(buf) free(buf)
@ -151,7 +150,8 @@ pub fn read_pkg(pkg_path string) ?Pkg {
} }
C.archive_read_data(a, buf, size) 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) ? pkg_info = parse_pkg_info_string(pkg_text) ?
} else { } else {
C.archive_read_data_skip(a) C.archive_read_data_skip(a)