Skip to content

Commit

Permalink
GDALDataset::GetProjectionRef() and GetGCPProjection(): add locking o…
Browse files Browse the repository at this point in the history
…n thread-safe dataset
  • Loading branch information
rouault committed Sep 19, 2024
1 parent bcd2b70 commit 83fca23
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions gcore/gdaldataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <cstring>
#include <algorithm>
#include <map>
#include <mutex>
#include <new>
#include <set>
#include <string>
Expand Down Expand Up @@ -114,6 +115,8 @@ class GDALDataset::Private
GIntBig nTotalFeatures = TOTAL_FEATURES_NOT_INIT;
OGRLayer *poCurrentLayer = nullptr;

std::mutex m_oMutexWKT{};

char *m_pszWKTCached = nullptr;
OGRSpatialReference *m_poSRSCached = nullptr;
char *m_pszWKTGCPCached = nullptr;
Expand Down Expand Up @@ -1166,6 +1169,11 @@ const char *GDALDataset::GetProjectionRef() const
{
return "";
}

// If called on a thread-safe dataset, we might be called by several
// threads, so make sure our accesses to m_pszWKTCached are protected
// by a mutex.
std::lock_guard oLock(m_poPrivate->m_oMutexWKT);
if (m_poPrivate->m_pszWKTCached &&
strcmp(pszWKT, m_poPrivate->m_pszWKTCached) == 0)
{
Expand Down Expand Up @@ -1831,6 +1839,11 @@ const char *GDALDataset::GetGCPProjection()
{
return "";
}

// If called on a thread-safe dataset, we might be called by several
// threads, so make sure our accesses to m_pszWKTCached are protected
// by a mutex.
std::lock_guard oLock(m_poPrivate->m_oMutexWKT);
if (m_poPrivate->m_pszWKTGCPCached &&
strcmp(pszWKT, m_poPrivate->m_pszWKTGCPCached) == 0)
{
Expand Down

0 comments on commit 83fca23

Please sign in to comment.