mirror of
https://github.com/XRPLF/rippled.git
synced 2026-08-21 22:30:57 +00:00
fix memory leak in LocalValue
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
This commit is contained in:
@@ -233,7 +233,7 @@ jobs:
|
||||
env:
|
||||
BUILD_NPROC: ${{ steps.nproc.outputs.nproc }}
|
||||
run: |
|
||||
./xrpld --unittest --unittest-jobs "${BUILD_NPROC}"
|
||||
./xrpld --unittest
|
||||
|
||||
# Pipeline should fail if the separate tests failed.
|
||||
- name: Check results of the SeparateTests
|
||||
|
||||
@@ -42,11 +42,29 @@ struct LocalValues
|
||||
std::unordered_map<void const*, std::unique_ptr<BasicValue>> values;
|
||||
};
|
||||
|
||||
// Wrapper to ensure proper cleanup when thread exits
|
||||
struct LocalValuesHolder
|
||||
{
|
||||
LocalValues* ptr = nullptr;
|
||||
|
||||
~LocalValuesHolder()
|
||||
{
|
||||
if (ptr && !ptr->onCoro)
|
||||
delete ptr;
|
||||
}
|
||||
};
|
||||
|
||||
inline LocalValuesHolder&
|
||||
getLocalValuesHolder()
|
||||
{
|
||||
thread_local LocalValuesHolder holder;
|
||||
return holder;
|
||||
}
|
||||
|
||||
inline LocalValues*&
|
||||
getLocalValuesPtr()
|
||||
{
|
||||
thread_local LocalValues* ptr = nullptr;
|
||||
return ptr;
|
||||
return getLocalValuesHolder().ptr;
|
||||
}
|
||||
|
||||
inline LocalValues*
|
||||
|
||||
Reference in New Issue
Block a user