Skip to content

loader: free handle and type maps of loaders that were never initialized - #911

Open
bhuvan-somisetty wants to merge 1 commit into
metacall:developfrom
bhuvan-somisetty:fix/path-overflow-test-leak
Open

bhuvan-somisetty wants to merge 1 commit into
metacall:developfrom
bhuvan-somisetty:fix/path-overflow-test-leak

Conversation

@bhuvan-somisetty

@bhuvan-somisetty bhuvan-somisetty commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Follow up to #910. With memcheck failing on leaks now, metacall-path-overflow-test was the only core test failing, with 176 bytes definitely lost from loader_impl_allocate.

The ExecutionPathOverflow test calls metacall_execution_path("mock", ...) without loading anything, so the mock loader gets created but never initialized. In loader_impl_destroy the loader's own destroy only runs when init == 0, and that's the one that ends up calling loader_impl_destroy_objects through loader_unload_children. So for a loader that was never initialized, handle_impl_path_map, handle_impl_map, handle_impl_init_order and type_info_map were never freed. Now it calls loader_impl_destroy_objects directly in that case. A loader that failed to initialize goes through the same path, so it's covered too.

Tested locally: MEMCHECK_TEST=metacall-path-overflow-test make memcheck goes from 176 bytes definitely lost to 0 errors, full make memcheck passes all 37 tests, and the ASan build passes all 41 tests.

loader_impl_destroy only calls the loader's destroy when it was
initialized, and that destroy is what ends up calling
loader_impl_destroy_objects. A loader that only got created (e.g. by
calling metacall_execution_path without loading anything) skipped it,
leaking handle_impl_path_map, handle_impl_map, handle_impl_init_order
and type_info_map. Found by valgrind in metacall-path-overflow-test.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

1 participant