more ASAN fixes

Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
This commit is contained in:
Pratik Mankawde
2026-02-05 13:40:26 +00:00
parent bbb03e153e
commit fd53813746
5 changed files with 55 additions and 7 deletions

View File

@@ -54,12 +54,8 @@ struct LocalValuesHolder
}
};
inline LocalValuesHolder&
getLocalValuesHolder()
{
thread_local LocalValuesHolder holder;
return holder;
}
LocalValuesHolder&
getLocalValuesHolder();
inline LocalValues*&
getLocalValuesPtr()

View File

@@ -139,6 +139,13 @@ public:
template <typename T>
ScopedStream(Stream const& stream, T const& t);
/** Overload for const char* to ensure immediate copy.
This prevents stack-use-after-scope issues when the source
pointer becomes invalid before the stream buffer operations
complete (e.g., during buffer reallocation).
*/
ScopedStream(Stream const& stream, char const* t);
ScopedStream(Stream const& stream, std::ostream& manip(std::ostream&));
ScopedStream&
@@ -159,6 +166,18 @@ public:
std::ostream&
operator<<(T const& t) const;
/** Overload for const char* to ensure immediate copy.
This prevents stack-use-after-scope issues when the source
pointer becomes invalid before the stream buffer operations
complete (e.g., during buffer reallocation).
*/
std::ostream&
operator<<(char const* t) const
{
m_ostream << std::string(t);
return m_ostream;
}
private:
Sink& m_sink;
Severity const m_level;
@@ -239,6 +258,17 @@ public:
template <typename T>
ScopedStream
operator<<(T const& t) const;
/** Overload for const char* to ensure immediate copy.
This prevents stack-use-after-scope issues when the source
pointer becomes invalid before the stream buffer operations
complete (e.g., during buffer reallocation).
*/
ScopedStream
operator<<(char const* t) const
{
return ScopedStream(*this, t);
}
/** @} */
private:

View File

@@ -0,0 +1,14 @@
#include <xrpl/basics/LocalValue.h>
namespace xrpl {
namespace detail {
LocalValuesHolder&
getLocalValuesHolder()
{
thread_local LocalValuesHolder holder;
return holder;
}
} // namespace detail
} // namespace xrpl

View File

@@ -118,6 +118,14 @@ Journal::ScopedStream::ScopedStream(Stream const& stream, std::ostream& manip(st
m_ostream << manip;
}
Journal::ScopedStream::ScopedStream(Stream const& stream, char const* t) : ScopedStream(stream.sink(), stream.level())
{
// Convert to std::string immediately to ensure the data is copied.
// This prevents stack-use-after-scope issues when the source pointer
// becomes invalid before stream buffer operations(like reallocation) complete.
m_ostream << std::string(t);
}
Journal::ScopedStream::~ScopedStream()
{
std::string const& s(m_ostream.str());

View File

@@ -6,7 +6,7 @@
namespace xrpl {
static uint256 const&
static uint256 const
depthMask(unsigned int depth)
{
enum { mask_size = 65 };