How to cope with the error of currupted heap(in debug mode) which arise due to different build flags of libraries involved in a project

StackOverflow https://stackoverflow.com/questions/16182003

Question

Brief introduction:
I am refactoring win32 application, I use VS 2008. The application consists of both of my own dll and 3-rd party dll`s.

Issue:
When I run the application in the debug mode and execute some action the error is raised: the application programm has triggered a breakpoint, heap is corrupted.

Actions undertaken:
I have searched the internet and found that this error may be because of different build flags (multi-threaded debug /MD and multi-threaded debug dll /MDd) were used for dlls within the project(which results that they use different c runtime libraries, and for each library own list for work with memory is maintained this therfore can lead to the heap corruption). I have checked my dlls - they all have the same flag: debug multithreaded dll. So I think that one of the 3-rd party DLL maybe was built with multi-threaded debug flag.

Questions:

  • Is it possible to find out with what flag 3-rd party library was built, if so how can I do this.
  • How can I sort you my issue of different build flags?
  • Is my guess about that error is due to different build flags is correct?
Was it helpful?

Solution

Is it possible to find out with what flag 3-rd party library was built, if so how can I do this

Yes. C or C++ DLLs built with Visual Studio versions 2005 and 2008 require a manifest that states what version of the C runtime DLL they need. You can see it with VS, File + Open + File, select the DLL and open the node labeled "RT_MANIFEST". Resource ID 2 is the manifest that states the type and version of the CRT. It should match yours. Export it to make it easier to read. If it is missing then it either wasn't built with /MD or used a completely different version of VS, which in itself is bad news.

How can I sort you my issue of different build flags?

You can't. You'll need to contact the 3rd party and request a build that's compatible with yours.

Is my guess about that error is due to different build flags is correct?

It is possible but not terribly likely. Having a mismatch does not automatically cause a crash, a programmer can certainly design the DLL interface so that's never an issue. You can typically tell from the function signature and documentation. The problem case is where the DLL allocates an object and you are supposed to release it. It will be obvious when the function returns a pointer. Or a standard C++ class library object like std::string. Less obvious is when it throws an exception. Such a problem is also highly repeatable, it will bomb consistently, not occasionally.

The biggest mistake you are making is asking this question here. You should be talking to a programmer employed by that 3rd party that has worked on this DLL. He'll know the exact answer to your questions and can very easily solve your problem. If you cannot get this kind of support then you should not be using these DLLs, they'll make your life miserable for a long time to come.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top