Opened 19 years ago

Closed 18 years ago

#1476 closed defect (fixed)

Usage of different heaps causes memory leak with SWIG C# on Win32

Reported by: szekerest Owned by: szekerest
Priority: normal Milestone: 4.8 release
Component: MapScript-SWIG Version: 4.6
Severity: major Keywords:
Cc:

Description

Calling mapObj.GetProjection() causes unexpected break using the debug build 
of SWIG mapscript with C#.

The reason of the problem is that the returned string allocated in libmap.dll 
and freed in mapscript.dll using different heaps with CRT.

The resulting behavious is that the returning string will not be freed at all.

This issue applies to all off the functions passing memory blocks using this 
way.

This problem could be resolved by replacing free() to msFree() in 
CSharp_mapObj_getProjection, but a more general soution would be expected.

Change History (8)

comment:1 by sgillies@…, 19 years ago

Thanks for the report, Tamas. I'll help as much as I can.

Frank's suggestion of making sure libmap.dll and mapscript.dll are completely in
line won't work?

comment:2 by szekerest, 19 years ago

Sean,

Frank suggested to compile libmap.dll and mapscript.dll to link CRT 
dynamically (/MD) which finally worked for me. However compiling either of 
them using CRT statically will not work, because the dll's will use separate 
heap.

In general the following condirions should be met:

1. CRT is used with dll /MD (not statically linked)
2. Both of the modules use the same version (eg. msvcrt.dll or
msvcr71.dll), suggested to compile with the same compiler version.

VS 6.0 will link to msvcrt.dll, VS.NET will linkt to msvcr71.dll by default.

So the makefile of mapscript might be modified accordingly.

I recommended to consider using malloc and free in the same module if so the 
statements above will fall out of scope.

Tamas

comment:3 by sgillies@…, 18 years ago

Milestone: FUTURE
Severity: criticalminor
Delaying to after 4.8.

comment:4 by sgillies@…, 18 years ago

Resolution: wontfix
Status: newclosed
Solution is to always use the same CRT. Tamas agrees.

comment:5 by szekerest, 18 years ago

Keywords: VERIFIED added
Milestone: FUTURE4.8 release
Severity: minormajor
Reopening since at least MS-CVS, MS-4-8, hobu's buildkit and ms4w suffers from this 
problem.

comment:6 by szekerest, 18 years ago

Keywords: VERIFIED removed
Resolution: wontfix
Status: closedreopened
NC

comment:7 by szekerest, 18 years ago

Owner: changed from sgillies@… to szekerest
Status: reopenednew
Reassigned to Tamas Szekeres

comment:8 by szekerest, 18 years ago

Resolution: fixed
Status: newclosed
Changed csharp/makefile.vc to use the OPTFLAGS from nmake.opt, ensuring to
compile libmap.dll and mapscript.dll with the same options.


Note: See TracTickets for help on using tickets.