Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5 allocations not freed running "client" example #52

Open
yay opened this issue Jul 31, 2024 · 0 comments
Open

5 allocations not freed running "client" example #52

yay opened this issue Jul 31, 2024 · 0 comments

Comments

@yay
Copy link
Contributor

yay commented Jul 31, 2024

Running this example https://github.com/laytan/odin-http/blob/main/examples/client/main.odin

with

main :: proc() {
	track(run)
}

run :: proc() {
   // example code
}

track :: proc(code: proc()) {
	track: mem.Tracking_Allocator
	mem.tracking_allocator_init(&track, context.allocator)
	context.allocator = mem.tracking_allocator(&track)

	defer {
		if len(track.allocation_map) > 0 {
			fmt.eprintf("=== %v allocations not freed: ===\n", len(track.allocation_map))
			for _, entry in track.allocation_map {
				fmt.eprintf("- %v bytes @ %v\n", entry.size, entry.location)
			}
		}
		if len(track.bad_free_array) > 0 {
			fmt.eprintf("=== %v incorrect frees: ===\n", len(track.bad_free_array))
			for entry in track.bad_free_array {
				fmt.eprintf("- %p @ %v\n", entry.memory, entry.location)
			}
		}
		fmt.printf("Peak memory allocated: %v\n", track.peak_memory_allocated)
		mem.tracking_allocator_destroy(&track)
	}

	code()
}

results in

=== 5 allocations not freed: ===
- 108 bytes @ /Users/vitaly/projects/odin-http/http.odin:165:11:
- 11 bytes @ /Users/vitaly/projects/odin-http/headers.odin:100:7:
- 161 bytes @ /Users/vitaly/projects/odin-http/http.odin:165:11:
- 11 bytes @ /Users/vitaly/projects/odin-http/headers.odin:100:7:
- 311 bytes @ /Users/vitaly/projects/odin-http/http.odin:165:11:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant