Visual Studio and .NET Framework Home
_com_error incorrectly frees memory with HeapFree instead of LocalFree
6/10/2009 12:33:45 PM
User(s) can reproduce this bug
_com_error internaly uses "FormatMessage" with "FORMAT_MESSAGE_ALLOCATE_BUFFER" to get the error message for a specific error code.
If "FormatMessage" allocates the memory of the string, the called (in this case _com_error) must free this memory with "LocalFree". But the destructor frees the memory with "HeapFree" with the process heap. This is wrong and causes in memory-checking tools errors.
Until VS2003 then behavior was correct. The problem appears starting with VS2005.
See also previous bug in VS2008:
(It was promised to be solved in VS2008 SP1...)
Visual Studio Team System 2010 Beta 1
Operating System Language
Steps to Reproduce
Here is a small example:
Please debug into the destructor of "_com_error" and you will see that the memory is wrongly freed with HeapFree instead of LocalFree!
comdef.h - line 162
The memory is freed with "HeapFree".
The memory from FormatMessage must be free with "LocalFree".
TAP Code (if applicable)
You can indicate your satisfaction with how Microsoft handled this issue by completing this quick
3 question survey
to post a comment.
Please enter a comment.
on 6/12/2009 at 4:26 PM
Thanks for the report. This has now been fixed for Visual Studio 2010. The fix was originally added to Visual Studio 2008 SP1 and was accidentally not ported over to 2010.
Visual C++ Libraries Development
on 6/11/2009 at 10:11 PM
Thanks for your feedback.
We are escalating this issue to the appropriate group within the Visual Studio Product Team for triage and resolution.
These specialized experts will follow-up with your issue.
to post a workaround.
Please enter a workaround.
© 2013 Microsoft