Skip to content

Commit

Permalink
Merge pull request #2260 from ollira/fix-proj_context_get_database_me…
Browse files Browse the repository at this point in the history
…tadata

Fix access violation in proj_context_get_database_metadata
  • Loading branch information
rouault authored Jun 10, 2020
2 parents 144a611 + adeca91 commit adc18ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/iso19111/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ const char *proj_context_get_database_metadata(PJ_CONTEXT *ctx,
// temporary variable must be used as getDBcontext() might create
// ctx->cpp_context
auto osVal(getDBcontext(ctx)->getMetadata(key));
if (osVal == nullptr) {
ctx->cpp_context->autoCloseDbIfNeeded();
return nullptr;
}
ctx->cpp_context->lastDbMetadataItem_ = osVal;
ctx->cpp_context->autoCloseDbIfNeeded();
return ctx->cpp_context->lastDbMetadataItem_.c_str();
Expand Down
3 changes: 3 additions & 0 deletions test/unit/test_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2616,6 +2616,9 @@ TEST_F(CApi, proj_cs_get_axis_info) {
TEST_F(CApi, proj_context_get_database_metadata) {
EXPECT_TRUE(proj_context_get_database_metadata(m_ctxt, "IGNF.VERSION") !=
nullptr);

EXPECT_TRUE(proj_context_get_database_metadata(m_ctxt, "FOO") ==
nullptr);
}

// ---------------------------------------------------------------------------
Expand Down

0 comments on commit adc18ae

Please sign in to comment.