[Gdal-dev] C# Osr.GetProjectionMethodParameterList Access Violation

Diaren diarenwhan at yahoo.co.uk
Thu Jun 4 08:01:45 EDT 2009


Hi I've been building a projection dialog box in C# Windows, and have come
across a bug/problem with the generated swig wrappers for
GetProjectionMethodParameterList / OPTGetParameterList. The problem is that
the generated Swig Wrapper osr_wrap.cpp frees the Username passed back from
OPTGetParameterList which is a static string.

ogr_opt.cpp in OPTGetParameterList
----------------------------------
457:   if( ppszUserName != NULL )
                *ppszUserName = (char *)papszProjectionDefinitions[i];     
// <=== Static array of strings


ogr_wrap.cpp in CSharp_GetProjectionMethodParameterList
--------------------------------------------------------
976:    result = (char **)OPTGetParameterList(arg1,arg2);    // arg2 is
ppszUserName from above
          ...
          jresult = result; 
          {
             /* %typemap(argout) (char **argout) */
             char* temp_string;
             temp_string = SWIG_csharp_string_callback(*arg2);
             if (*arg2)
               free(*arg2);           // <===== Freeing static string
             *arg2 = temp_string;
          }
          return jresult;

Problem is I don't know the first thing about how swig works... and If I
modify the OPTGetParameterList to use CPLStrdup or something, then that will
cause problems for other code which knows Username is a static string and
doesn't need freeing.

So any swig experts that can modify the generated wrapper to not free arg2?
or is OPTGetParameterList supposed to allocate the string passed back
through Username?

-- 
View this message in context: http://n2.nabble.com/C--Osr.GetProjectionMethodParameterList-Access-Violation-tp3024324p3024324.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.



More information about the gdal-dev mailing list