This is an archive of the discontinued LLVM Phabricator instance.

Fix memory leaks in address sanitizer darwin tests
ClosedPublic

Authored by fjricci on Apr 12 2017, 7:31 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

fjricci created this revision.Apr 12 2017, 7:31 AM
alekseyshl accepted this revision.Apr 12 2017, 8:37 AM
alekseyshl added inline comments.
test/asan/TestCases/Darwin/malloc_set_zone_name-mprotect.cc
52 ↗(On Diff #94966)

Who's holding (and leaking) the buffer?

This revision is now accepted and ready to land.Apr 12 2017, 8:37 AM
fjricci added inline comments.Apr 12 2017, 8:44 AM
test/asan/TestCases/Darwin/malloc_set_zone_name-mprotect.cc
52 ↗(On Diff #94966)

From looking at the only malloc_set_zone_name source I could find (https://opensource.apple.com/source/Libc/Libc-320.1.3/gen/malloc.c), it looks like libc itself is holding a copy, which it frees whenever the name is overwritten. For some reason, malloc_destroy_zone doesn't free that buffer (I assume it should).

fjricci added inline comments.Apr 12 2017, 8:46 AM
test/asan/TestCases/Darwin/malloc_set_zone_name-mprotect.cc
52 ↗(On Diff #94966)

Another alternative which would probably work would be calling 'free(malloc_get_zone_name(zone))`, but that seemed hackier.

alekseyshl added inline comments.Apr 12 2017, 9:36 AM
test/asan/TestCases/Darwin/malloc_set_zone_name-mprotect.cc
52 ↗(On Diff #94966)

Looking at the code, it's not a leak. The zone name buffer is allocated within the zone itself, so destroying the zone effectively deallocates the name too.

kubamracek added inline comments.Apr 12 2017, 9:41 AM
test/asan/TestCases/Darwin/malloc_set_zone_name-mprotect.cc
52 ↗(On Diff #94966)

This leaks because we have an interceptor for malloc_destroy_zone, which doesn't really destroy the zone, nor does it free the name (see sanitizer_malloc_mac.inc). Could this be fixed in the interceptor instead?

alekseyshl added inline comments.Apr 12 2017, 10:00 AM
test/asan/TestCases/Darwin/malloc_set_zone_name-mprotect.cc
52 ↗(On Diff #94966)

Right, what I meant to say, the actual malloc does not leak the name.

Fixing it in the interceptor sounds like a better idea.

fjricci added inline comments.Apr 12 2017, 10:03 AM
test/asan/TestCases/Darwin/malloc_set_zone_name-mprotect.cc
52 ↗(On Diff #94966)

Changing the interceptor to free the name does fix the leak, I'll pull that out into a separate patch.

kubamracek added inline comments.Apr 12 2017, 10:05 AM
test/asan/TestCases/Darwin/malloc_set_zone_name-mprotect.cc
52 ↗(On Diff #94966)

Great, thanks!

fjricci updated this revision to Diff 94993.Apr 12 2017, 10:05 AM

Remove hack to clear malloc zone name

kubamracek accepted this revision.Apr 12 2017, 10:14 AM
This revision was automatically updated to reflect the committed changes.