MapServer / MapServer-import

3 stars 2 forks source link

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

Open tbonfort opened 12 years ago

tbonfort commented 12 years ago

Reporter: szekerest Date: 2005/09/21 - 17:26

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.
tbonfort commented 12 years ago

Author: sgillies@frii.com Date: 2005/09/22 - 19:12

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?
tbonfort commented 12 years ago

Author: szekerest Date: 2005/09/22 - 21:27

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
tbonfort commented 12 years ago

Author: sgillies@frii.com Date: 2005/11/22 - 23:24

Delaying to after 4.8.
tbonfort commented 12 years ago

Author: sgillies@frii.com Date: 2006/02/23 - 22:19

Solution is to always use the same CRT. Tamas agrees.
tbonfort commented 12 years ago

Author: szekerest Date: 2006/04/08 - 00:37


Reopening since at least MS-CVS, MS-4-8, hobu's buildkit and ms4w suffers from this 
problem.
tbonfort commented 12 years ago

Author: szekerest Date: 2006/04/08 - 00:39


NC
tbonfort commented 12 years ago

Author: szekerest Date: 2006/04/08 - 00:40


Reassigned to Tamas Szekeres
tbonfort commented 12 years ago

Author: szekerest Date: 2006/04/10 - 16:05


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