Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSRExportToProj4 should not allocate a GMT variable and let GMT free it. That's a Boom on Windows. #1094

Closed
joa-quim opened this issue May 21, 2020 · 3 comments

Comments

@joa-quim
Copy link
Contributor

I'm getting crash with mbgrid at the end when it calls GMT to free header->ProjRefPROJ4. Surprisingly this only occurs with GMT debug builds. I say surprisingly because it should happen also with normal builds. The issue, I think, is that in mb_readwritegrd()

    if ((eErr = OSRExportToProj4(hSRS, &header->ProjRefPROJ4)) != OGRERR_NONE) {
      fprintf(stderr, "Failed to convert the SRS to Proj syntax\n");
    }
    OSRDestroySpatialReference(hSRS);
  }
  fprintf(stderr,"header->ProjRefPROJ4:%s\n", header->ProjRefPROJ4);

but that allocates the pointer header->ProjRefPROJ4 in GDAL but that pointer is then freed in GMT. On Windows this is a no-no. One cannot cross-dlls like that. Memory allocated in one dll must be freed in it.

On GMT we deal with that case using a temporary variable, like

		if (OSRImportFromWkt(hSRS, &pszProjection) == CE_None) {
			OSRExportToProj4(hSRS, &pszResult);
			Ctrl->ProjRefPROJ4 = strdup(pszResult);
			CPLFree(pszResult);
		}

also, there is no need to

fprintf(stderr,"header->ProjRefPROJ4:%s\n", header->ProjRefPROJ4);
@dwcaress
Copy link
Owner

Thanks. I tried to fix this with #1095.

@joa-quim
Copy link
Contributor Author

Sorry, should have thought on that. It's still no good because the same problem remains. Now it's allocated in MB and freed in GMT. But we happen to have a function that saves the situation. Please use

header->ProjRefPROJ4 = gmt_strdup_noquote(pszResult);

Sorry for not submitting PRs but I have a very old fork.

@dwcaress
Copy link
Owner

Try again with #1096.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants