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.
精彩评论