Skip to content

Use malloc zone for Darwin realloc hook#3637

Open
fallintoplace wants to merge 1 commit into
apple:mainfrom
fallintoplace:fix/darwin-zone-realloc
Open

Use malloc zone for Darwin realloc hook#3637
fallintoplace wants to merge 1 commit into
apple:mainfrom
fallintoplace:fix/darwin-zone-realloc

Conversation

@fallintoplace

Copy link
Copy Markdown
Contributor

Motivation

The Darwin allocation-counting hook for malloc_zone_realloc accepted a malloc zone, but delegated to plain realloc. That ignored the zone argument and could reallocate through the wrong allocator for zone-specific allocation paths.

Modification

Call malloc_zone_realloc(zone, ptr, size) from replacement_malloc_zone_realloc.

This also adds a small Darwin C executable test target with a custom malloc zone. The test verifies that replacement_malloc_zone_realloc dispatches through the requested zone's realloc callback.

Result

Darwin zone-specific realloc calls now preserve the requested malloc zone while keeping the existing allocation/free counter behavior.

Validation

  • swift run --package-path IntegrationTests/allocation-counter-tests-framework/template/HookedFunctionsDoHook HookedFunctionsDarwinTests
  • swift build --package-path IntegrationTests/allocation-counter-tests-framework/template/HookedFunctionsDoHook
  • git diff --check

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