From 3175b3a23ba23085b5c412a1e61db3718dcbd186 Mon Sep 17 00:00:00 2001 From: IllusionMan1212 Date: Sun, 25 May 2025 22:44:14 +0200 Subject: [PATCH] fix: clean up all memory leaks. use tracking allocator in example --- README.md | 2 -- blurhash.odin | 20 +++++++++----------- example/main.odin | 43 +++++++++++++++++++++++++++++++++++++++---- 3 files changed, 48 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 013d0bb..fe5474a 100644 --- a/README.md +++ b/README.md @@ -2,5 +2,3 @@ BlurHash Implementation in Odin -### TODO -- [ ] Clean up memory leaks diff --git a/blurhash.odin b/blurhash.odin index 73ff962..d67b314 100644 --- a/blurhash.odin +++ b/blurhash.odin @@ -61,9 +61,7 @@ base83_decode_str :: proc(str: string) -> int { base83_decode :: proc{base83_decode_str, base83_decode_byte} @(private) -base83_encode :: proc(value, length: int, allocator := context.allocator) -> string { - b := strings.builder_make_none(allocator) - +base83_encode :: proc(b: ^strings.Builder, value, length: int, allocator := context.allocator) { pow :: proc(base, exp: int) -> int { base := base exp := exp @@ -80,10 +78,8 @@ base83_encode :: proc(value, length: int, allocator := context.allocator) -> str for i in 1..=length { digit := (value / pow(83, length - i)) % 83 - strings.write_byte(&b, ENC_TABLE[digit]) + strings.write_byte(b, ENC_TABLE[digit]) } - - return strings.to_string(b) } @(private) @@ -168,6 +164,7 @@ decode :: proc(blurhash: string, width, height: int, punch := 1.0, allocator := colors_size := num_x * num_y colors := make([][3]f32, colors_size) + defer delete(colors) for iter in 0..