MFC unsafely uses GetModuleHandle behind the scenes, causing crash - by Gigaplex

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.


2
0
Sign in
to vote
ID 711714 Comments
Status Closed Workarounds
Type Bug Repros 1
Opened 12/5/2011 5:32:57 PM
Access Restriction Public
Moderator Decision Sent to Engineering Team for consideration

Description

According to the documentation of the GetModuleHandle function, it is unsafe to assume that the handle returned remains valid between the time the handle is returned and the time it is used (most relevant in multithreaded applications). Unfortunately, MFC uses GetModuleHandle unsafely behind the scenes in the class CDllIsolationWrapperBase (afxcomctl32.h).

The CDllIsolationWrapperBase class first attempts to query and store for an extended period the handle to the module in question using GetModuleHandle, and if that fails it falls back to LoadLibrary. LoadLibrary increases the reference count, GetModuleHandle does not. If something temporarily loads the module before the first use of this class and unloads it later, the class assumes it's still valid and a crash is likely.
Sign in to post a comment.
Posted by Microsoft on 12/7/2011 at 10:37 AM
Hello,

Thanks for the report. This issue has been fixed in Visual Studio 11, because all of the CDllIsolationWrapperBase code has been removed. None of the code related to activation context remains, it has all been removed for Visual Studio 11. The isolation macros from Windows are used via the ISOLATION_AWARE_ENABLED macro.

Pat Brenner
Visual C++ Libraries Development
Posted by MS-Moderator07 [Feedback Moderator] on 12/6/2011 at 1:30 AM
Thanks for your feedback.

We are rerouting 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.
Posted by Gigaplex on 12/5/2011 at 7:14 PM
The attached repro project shows this in action, simply build the solution and use the "Open..." menu in the test application more than once.
Posted by MS-Moderator01 on 12/5/2011 at 5:43 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)