Search

Heap corruption when CObject-derived class throws from constructor when being called from make_shared by McNitt

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 716468
Opened: 1/4/2012 6:09:25 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
0
User(s) can reproduce this bug
using std:make_shared to allocate an object that throws during the constructor causes a heap corruption.
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling version

Visual Studio 2010 SP1

Steps to reproduce

    ////////////////////////////////////////////////////////////////////////////////
    // Case 4: the problem. Heap corruption message is displayed if the constructor of CObject-derived class throws while it is
    // being constructed with make_shared. Perhaps this is related to make_shared using placement new?
    try
    {
        // Heap corruption message will be displayed shortly.
        auto thrower = std::make_shared<ThrowerDerivedFromCObject>();
    }
    catch( std::exception& )
    {
        AfxMessageBox( _T("Caught Exception from Thrower. This will not be reached.") );
    }

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

Heap corrption message reported

Expected results

no heap corruption
File Attachments
File Name Submitted By Submitted On File Size  
make_shared_CObject_heap_corruption.zip 1/4/2012 11 KB
Sign in to post a comment.
Posted by Microsoft on 1/16/2012 at 5:40 PM
Hi,

Thanks for reporting this bug. We've already fixed it (back in August) and the fix will be available in VC11.

The problem, amusingly enough, was that make_shared<T>() invoked placement new with "new", which will consider class-specific operator new() implementations (or in this case, class-specific operator delete()). The fix was to use "::new", which is guaranteed to invoke "true placement new" at global scope (which is a no-op).

If you have any further questions, feel free to E-mail me at stl@microsoft.com .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by MS-Moderator07 [Feedback Moderator] on 1/4/2012 at 10:28 PM
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 MS-Moderator01 on 1/4/2012 at 6:42 AM
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)
Posted by McNitt on 1/4/2012 at 6:12 AM
We believe the problem is with placement new.
Sign in to post a workaround.