Skip to content

Commit

Permalink
Prevent use of thread specific data after destruction
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-webb committed Nov 6, 2024
1 parent 00d73bf commit 2a01934
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
9 changes: 1 addition & 8 deletions src/main/cpp/threadspecificdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,10 @@ using namespace LOG4CXX_NS::helpers;
struct ThreadSpecificData::ThreadSpecificDataPrivate{
ThreadSpecificDataPrivate()
: pNamePair(std::make_shared<NamePair>())
, isValid(true)
{
setThreadIdName();
setThreadUserName();
}
~ThreadSpecificDataPrivate()
{
isValid = false;
}
NDC::Stack ndcStack;
MDC::Map mdcMap;

Expand All @@ -64,8 +59,6 @@ struct ThreadSpecificData::ThreadSpecificDataPrivate{

void setThreadIdName();
void setThreadUserName();

bool isValid; // Is this object un-destructed?
};

/* Generate an identifier for the current thread
Expand Down Expand Up @@ -192,7 +185,7 @@ ThreadSpecificData* ThreadSpecificData::getCurrentData()
{
#if LOG4CXX_HAS_THREAD_LOCAL
thread_local ThreadSpecificData data;
return data.m_priv && data.m_priv->isValid ? &data : NULL;
return data.m_priv ? &data : NULL;
#elif APR_HAS_THREADS
void* pData = NULL;
if (APR_SUCCESS == apr_threadkey_private_get(&pData, APRInitializer::getTlsKey())
Expand Down
1 change: 1 addition & 0 deletions src/test/cpp/ndctestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
static log4cxx::NDC ndc("ndctest");

using namespace log4cxx;

LOGUNIT_CLASS(NDCTestCase)
{
static File TEMP;
Expand Down

0 comments on commit 2a01934

Please sign in to comment.