From 36c22393a4e3026bc84a5ee8d2230d1f6f78b83c Mon Sep 17 00:00:00 2001 From: CiD- Date: Tue, 15 Mar 2022 11:47:35 -0400 Subject: [PATCH] fix memory leak --- core/os/os2/path_linux.odin | 3 ++- tests/core/os2/test_os2.odin | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/os/os2/path_linux.odin b/core/os/os2/path_linux.odin index 85c39916f..889f7e447 100644 --- a/core/os/os2/path_linux.odin +++ b/core/os/os2/path_linux.odin @@ -112,7 +112,8 @@ _remove_all :: proc(path: string) -> Error { loop: for { res := unix.sys_getdents64(int(dfd), &buf[0], n) switch res { - case -22: //-EINVAL + case -EINVAL: + delete(buf) n *= 2 buf = make([]u8, n) continue loop diff --git a/tests/core/os2/test_os2.odin b/tests/core/os2/test_os2.odin index 0e0d3dcb5..e52351f03 100644 --- a/tests/core/os2/test_os2.odin +++ b/tests/core/os2/test_os2.odin @@ -2,6 +2,7 @@ package test_os2 import "core:os" import "core:fmt" +import "core:mem" import "core:os/os2" import "core:testing" import "core:intrinsics" @@ -49,10 +50,22 @@ when ODIN_TEST { main :: proc() { + track: mem.Tracking_Allocator + mem.tracking_allocator_init(&track, context.allocator) + context.allocator = mem.tracking_allocator(&track) + t: testing.T file_test(&t) path_test(&t) fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count) + + for _, leak in track.allocation_map { + fmt.printf("%v leaked %v bytes\n", leak.location, leak.size) + } + for bad_free in track.bad_free_array { + fmt.printf("%v allocation %p was freed badly\n", bad_free.location, bad_free.memory) + } + os.exit(TEST_fail > 0 ? 1 : 0) } @@ -215,6 +228,7 @@ path_test :: proc(t: ^testing.T) { symlink, err = os2.read_link("a/symlink_to_d") _expect_no_error(t, err) expect_value(t, symlink, "b/c/d") + delete(symlink) fd, err = os2.create("a/symlink_to_d/shnt.txt", 0o744) _expect_no_error(t, err)