Skip to content

Commit

Permalink
ogr_proj_p.cpp: make sure init() is called in OSRPJContextHolder() co…
Browse files Browse the repository at this point in the history
…nstructor to avoid potential use of default NULL PROJ context (refs #2691)
  • Loading branch information
rouault committed Jun 16, 2020
1 parent 1e29a15 commit e873aa2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions gdal/ogr/ogr_proj_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ struct OSRPJContextHolder
#endif

#if !defined(_WIN32)
OSRPJContextHolder(): curpid(getpid()) {}
OSRPJContextHolder(): curpid(getpid()) { init(); }
#else
OSRPJContextHolder() = default;
OSRPJContextHolder() { init(); }
#endif

~OSRPJContextHolder();
Expand Down Expand Up @@ -178,10 +178,13 @@ static OSRPJContextHolder& GetProjTLSContextHolder()
l_projContext.context = nullptr;
l_projContext.init();
#else
const auto osr_proj_logger_none = [](void *, int, const char *) {};
proj_log_func (l_projContext.context, nullptr, osr_proj_logger_none);
proj_context_set_autoclose_database(l_projContext.context, true);
// dummy call to cause the database to be closed
proj_context_get_database_path(l_projContext.context);
proj_context_set_autoclose_database(l_projContext.context, false);
proj_log_func (l_projContext.context, nullptr, osr_proj_logger);
#endif
}

Expand All @@ -193,7 +196,6 @@ static OSRPJContextHolder& GetProjTLSContextHolder()
PJ_CONTEXT* OSRGetProjTLSContext()
{
auto& l_projContext = GetProjTLSContextHolder();
l_projContext.init();
{
// If OSRSetPROJSearchPaths() has been called since we created the context,
// set the new search paths on the context.
Expand Down

0 comments on commit e873aa2

Please sign in to comment.