_com_error incorrectly frees memory with HeapFree instead of LocalFree - by Jochen Kalmbach

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 466042 Comments
Status Closed Workarounds
Type Bug Repros 1
Opened 6/10/2009 12:33:45 PM
Access Restriction Public


_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...)
Sign in to post a comment.
Posted by Microsoft 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.

Pat Brenner
Visual C++ Libraries Development
Posted by Microsoft 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.