Base: Fixed segfault on destructing cached string (#20563)

* Base: Fixed segfault on destructing cached string

Xerces default memory manager is deleted before destructing static local
variable and segfault.

---------

Co-authored-by: Chris Hennes <chennes@pioneerlibrarysystem.org>
This commit is contained in:
Kohei Takahashi
2025-05-16 02:23:03 +09:00
committed by GitHub
parent 238957fb16
commit b54898f05f
3 changed files with 58 additions and 3 deletions

View File

@@ -23,6 +23,11 @@
#include "PreCompiled.h"
#ifndef _PreComp_
#include <xercesc/framework/MemoryManager.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
#endif
#include "Exception.h"
#include "XMLTools.h"
@@ -128,3 +133,19 @@ void XMLTools::terminate()
{
transcoder.reset();
}
void* XStrMemoryManager::allocate(XMLSize_t size)
{
auto ptr = ::operator new(static_cast<size_t>(size),
static_cast<std::align_val_t>(alignof(XMLCh)),
std::nothrow);
if (ptr == nullptr && size != 0) {
throw XERCES_CPP_NAMESPACE::OutOfMemoryException();
}
return ptr;
}
void XStrMemoryManager::deallocate(void* p)
{
::operator delete(p);
}