From 939ba4cf0882291b8b35241ef6fc266ae74e9727 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Sat, 3 Aug 2024 15:17:29 +0200 Subject: [PATCH] os2: fix leak and always close directory --- core/os/os2/internal_util.odin | 2 +- core/os/os2/path_posix.odin | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/os/os2/internal_util.odin b/core/os/os2/internal_util.odin index ed65ab7e0..52e7522d1 100644 --- a/core/os/os2/internal_util.odin +++ b/core/os/os2/internal_util.odin @@ -76,7 +76,7 @@ concatenate :: proc(strings: []string, allocator: runtime.Allocator) -> (res: st for s in strings { n += len(s) } - buf := make([]byte, n) or_return + buf := make([]byte, n, allocator) or_return n = 0 for s in strings { n += copy(buf[n:], s) diff --git a/core/os/os2/path_posix.odin b/core/os/os2/path_posix.odin index 066ca1ddf..2fd289300 100644 --- a/core/os/os2/path_posix.odin +++ b/core/os/os2/path_posix.odin @@ -61,6 +61,7 @@ _remove_all :: proc(path: string) -> Error { if dir == nil { return _get_platform_error() } + defer posix.closedir(dir) for { posix.set_errno(.NONE) @@ -91,7 +92,6 @@ _remove_all :: proc(path: string) -> Error { if posix.rmdir(cpath) != .OK { return _get_platform_error() } - posix.closedir(dir) return nil }