fix memory leak in LocalValue

Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
This commit is contained in:
Pratik Mankawde
2026-02-04 13:17:31 +00:00
parent 26dd1fafe3
commit 49dcb6b60b
2 changed files with 21 additions and 3 deletions

View File

@@ -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

View File

@@ -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*