开发者

64-bit version of DLL crashes on memory free; 32-bit does not

I've coded a p开发者_如何学Crogram in C that uses the NX Open C library. I have to compile it into a .dll, and as a 32-bit .dll on a 32-bit machine, it works beautifully. However, when I put the same code in Visual Studio on a 64-bit machine and specify that it compile for 64-bit, and I run the program, it crashes on a line that frees some memory. When I comment out that line for the 64-bit version, it runs fine. The NX Open documentation indicates that this is memory I'm supposed to free.

My question is this: What causes this? Why does a program, coded exactly the same, crash on a memory free in its 64-bit version on a 64-bit machine, and not the 32-bit version on a 32-bit machine? Is this something I should have expected? Have I done something wrong that I can prevent? Or is it a symptom of a bigger problem?

Version info: I'm using Visual Studio 2005, NX 5.0.6.3, Windows XP SP3


This is most likely a memory corruption bug of some sort. You either:

  • deallocate the same memory twice

  • work with already freed memory (thereby corrupting new memory allocations)

  • write outside the allocated memory (thereby corrupting other allocations or the memory management structures)

It's likely that the bug exists in the 32-bit version as well but hasn't been discovered yet because it never damaged essential data.

It can be very hard to find such a bug. I therefore recommend using a memory debugger such as Purify, Valgrind or Insure++ to detect where the problematic memory accesses are.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜