I've been debugging a heap corruption exception in one of our applications. It just started happening last month (march 2015) on code that hasn't changed. windbg narrowed it down to some code where we are using pinvoke to invoke a zlib function from c#.
The code snippet is:
public class Info
{
[DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
private static extern string zlibVersion();
public static string Version { get { return zlibVersion(); } }
}
It looks like this code is from zlib.net source\contrib\dotzlib\DotZLib\DotZlib.cs which is a dotnet wrapper to zlib.dll.
Question: Any idea why this would cause a heap corruption? Is there a problem with the dotnet pinvoke? I would think a lot of other applications could be using this same wrapper. However I'm not finding others complaining about this on the internet.
Edit 1 - Here's the unmanaged interface from the zlib source (zlib.h):
ZEXTERN const char * ZEXPORT zlibVersion OF((void));