Opened 15 years ago
Closed 15 years ago
#3018 closed defect (fixed)
C# Osr.GetProjectionMethodParameterList / OPTGetParameterList Access Violation
Reported by: | Diaren | Owned by: | tamas |
---|---|---|---|
Priority: | normal | Milestone: | 1.6.2 |
Component: | CSharpBindings | Version: | 1.6.0 |
Severity: | normal | Keywords: | GetParameterList GetProjectionMethodParameterList |
Cc: |
Description
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;
Well I've learnt some swig and possibly solved the problem. It now doesn't crash, or try to free the static strings, tested on vista x86, x64 and XP x86. Can someone verify that this ok and maybe turn this into a proper patch or someting was against 1.6.0:
N.B. The same problem applies to GetParameterInfo which is also remedied below
typemaps_csharp.i +244: %typemap(argout) (char **staticstring) { /* %typemap(argout) (char **staticstring) */ *$1 = SWIG_csharp_string_callback(*$1); } osr.i: -229: %rename (GetProjectionMethodParameterList) OPTGetParameterList; %apply (char **CSL) {(char **)}; char **OPTGetParameterList( char *method, char **username ); %clear (char **); %rename (GetProjectionMethodParamInfo) OPTGetParameterInfo; void OPTGetParameterInfo( char *method, char *param, char **usrname, char **type, double *defaultval ); +229: %rename (GetProjectionMethodParameterList) OPTGetParameterList; %apply (char **CSL) {(char **)}; %apply (char **staticstring) {(char **username)}; char **OPTGetParameterList( char *method, char **username ); %clear (char **); %clear (char **username); %rename (GetProjectionMethodParamInfo) OPTGetParameterInfo; %apply (char **staticstring) {(char **usrname), (char **type)}; void OPTGetParameterInfo( char *method, char *param, char **usrname, char **type, double *defaultval ); %clear (char **usrname); %clear (char **type);
Change History (2)
comment:1 by , 15 years ago
Milestone: | → 1.6.2 |
---|---|
Status: | new → assigned |
comment:2 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Fixed in trunk r17180 and branch-1.6 r17181