mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 22:58:46 +00:00
fix memory leak
This commit is contained in:
@@ -112,7 +112,8 @@ _remove_all :: proc(path: string) -> Error {
|
|||||||
loop: for {
|
loop: for {
|
||||||
res := unix.sys_getdents64(int(dfd), &buf[0], n)
|
res := unix.sys_getdents64(int(dfd), &buf[0], n)
|
||||||
switch res {
|
switch res {
|
||||||
case -22: //-EINVAL
|
case -EINVAL:
|
||||||
|
delete(buf)
|
||||||
n *= 2
|
n *= 2
|
||||||
buf = make([]u8, n)
|
buf = make([]u8, n)
|
||||||
continue loop
|
continue loop
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package test_os2
|
|||||||
|
|
||||||
import "core:os"
|
import "core:os"
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
|
import "core:mem"
|
||||||
import "core:os/os2"
|
import "core:os/os2"
|
||||||
import "core:testing"
|
import "core:testing"
|
||||||
import "core:intrinsics"
|
import "core:intrinsics"
|
||||||
@@ -49,10 +50,22 @@ when ODIN_TEST {
|
|||||||
|
|
||||||
main :: proc()
|
main :: proc()
|
||||||
{
|
{
|
||||||
|
track: mem.Tracking_Allocator
|
||||||
|
mem.tracking_allocator_init(&track, context.allocator)
|
||||||
|
context.allocator = mem.tracking_allocator(&track)
|
||||||
|
|
||||||
t: testing.T
|
t: testing.T
|
||||||
file_test(&t)
|
file_test(&t)
|
||||||
path_test(&t)
|
path_test(&t)
|
||||||
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
|
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)
|
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")
|
symlink, err = os2.read_link("a/symlink_to_d")
|
||||||
_expect_no_error(t, err)
|
_expect_no_error(t, err)
|
||||||
expect_value(t, symlink, "b/c/d")
|
expect_value(t, symlink, "b/c/d")
|
||||||
|
delete(symlink)
|
||||||
|
|
||||||
fd, err = os2.create("a/symlink_to_d/shnt.txt", 0o744)
|
fd, err = os2.create("a/symlink_to_d/shnt.txt", 0o744)
|
||||||
_expect_no_error(t, err)
|
_expect_no_error(t, err)
|
||||||
|
|||||||
Reference in New Issue
Block a user