mirror of
https://github.com/apple/swift-nio
synced 2026-11-25 04:47:49 +00:00
Motivation: The allocation counter integration tests previously used a pretty crude malloc implementation for the case that malloc is needed whilst we resolve malloc from libc using dlsym. This implements a much better version and also allows us to actually use free. Previously we just leaked all the memory (which is okay as its just a test but in constrained environments this wouldn't scale as we might actually run out of memory). The reason we used to leak the memory is that given a pointer we couldn't figure out if that pointer was alloated using libc's malloc or our crude malloc implementation so we didn't know how to free. The new version fixes that as all the pointers vended from recursive_malloc live in one global block. That makes it trivial to check if a given pointer is allocated by recursive_malloc (lives in that block) or libc's malloc (doesn't live in the recursive_malloc block). Modifications: - implemented a better recursive_malloc function - make the allocation counter test actually free memory that can be freed Result: Less memory use in the allocation counter test.