Microsoft KB Archive/190149

= PRB: Access Violation in GetAmbientDisplayName =

Article ID: 190149

Article Last Modified on 9/18/2003

-

APPLIES TO

 Microsoft ActiveX Template Library 3.0, when used with:  Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Professional Edition

 Microsoft Visual C++ 6.0 Standard Edition

 Microsoft Visual C++ .NET 2003 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2002 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q190149

<div class="symptoms_section">

SYMPTOMS
An Access Violation may occur in GetAmbientDisplayName if the BSTR parameter passed to it is uninitialized. This is most likely to occur if the BSTR was declared as a local variable.

<div class="cause_section">

CAUSE
In Visual C++ 6. and Visual C++ .Net, the ATL implementation of GetAmbientDisplayName assumes that all non-NULL BSTRs are initialized, and passes them to ::SysFreeString. This assumption can cause problems because any uninitialized BSTR declared inside a function could be non-NULL.

<div class="resolution_section">

RESOLUTION
Set any uninitialized BSTRs to NULL before calling GetAmbientDisplayName.

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

MORE INFORMATION
The ATL implementation of GetAmbientDisplayName in Visual C++ 5.0 assumes all BSTRs are uninitialized and does not free memory before using them, which can cause leaks. Also, no memory is allocated for the BSTR and the value of the BSTR is set to memory that is then freed, which can cause access violations.

These problems have been corrected in Visual C++ 6.0.

(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Kelly Marie Ward, Microsoft Corporation.

Keywords: kbprb KB190149

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.