Fix memory leak in Stripe destructor#12746
Closed
bneradt wants to merge 1 commit intoapache:masterfrom
Closed
Conversation
Add a destructor to the Stripe class to properly free the directory
memory allocated in _init_directory(). The memory was allocated via
ats_memalign or ats_alloc_hugepage but never freed when Stripe objects
were destroyed. A new private member tracks whether hugepages were used
so the destructor can call the appropriate free function. This was
discovered via an infrequent ASAN failure in the
cache_disk_replacement_stability regression test, which reported a ~27GB
leak from 24 StripeSM objects that went out of scope without releasing
their directory buffers.
```
=================================================================
==5207==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 29272965120 byte(s) in 24 object(s) allocated from:
#0 0x7f8b9cd1669c in __interceptor_posix_memalign (/lib64/libasan.so.6+0xb569c)
#1 0xa69d99 in ats_memalign(unsigned long, unsigned long) ../src/tscore/ink_memory.cc:108
#2 0xfd96e2 in Stripe::_init_directory(unsigned long, int, int) ../src/iocore/cache/Stripe.cc:159
#3 0xfd905f in Stripe::Stripe(CacheDisk*, long, long, int, int) ../src/iocore/cache/Stripe.cc:97
#4 0xfdc7ef in StripeSM::StripeSM(CacheDisk*, long, long, int, int) ../src/iocore/cache/StripeSM.cc:120
#5 0xff8c81 in std::_MakeUniq<StripeSM>::__single_object std::make_unique<StripeSM, CacheDisk*, long, int>(CacheDisk*&&, long&&, int&&) (/tmp/ats-quiche/bin/traffic_server+0xff8c81)
#6 0xff4797 in RegressionTest_cache_disk_replacement_stability(RegressionTest*, int, int*) ../src/iocore/cache/CacheTest.cc:458
#7 0xa4c994 in start_test ../src/tscore/Regression.cc:83
#8 0xa4cd6c in RegressionTest::run(char const*, int) ../src/tscore/Regression.cc:106
#9 0xa1a2a8 in mainEvent ../src/traffic_server/traffic_server.cc:1570
#10 0x9fd61a in Continuation::handleEvent(int, void*) ../include/iocore/eventsystem/Continuation.h:228
apache#11 0x13373e7 in EThread::process_event(Event*, int, long) ../src/iocore/eventsystem/UnixEThread.cc:171
apache#12 0x133809c in EThread::execute_regular() ../src/iocore/eventsystem/UnixEThread.cc:288
apache#13 0x1338a7b in EThread::execute() ../src/iocore/eventsystem/UnixEThread.cc:383
apache#14 0x13356e8 in spawn_thread_internal ../src/iocore/eventsystem/Thread.cc:75
apache#15 0x7f8b9abeb1c9 in start_thread (/lib64/libpthread.so.0+0x81c9)
```
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a destructor to the Stripe class to properly free the directory memory allocated in _init_directory(). The memory was allocated via ats_memalign or ats_alloc_hugepage but never freed when Stripe objects were destroyed. A new private member tracks whether hugepages were used so the destructor can call the appropriate free function. This was discovered via an infrequent ASAN failure in the
cache_disk_replacement_stability regression test, which reported a ~27GB leak from 24 StripeSM objects that went out of scope without releasing their directory buffers.