Potential bug with containers of pairs/tuples containing smart pointers - by Matt.Horn

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.


1
0
Sign in
to vote
ID 835690 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 3/17/2014 2:34:42 PM
Access Restriction Public

Description

In Visual Studio 2013, the following compiles without warnings but results in odd behavior.

#include <memory>
#include <map>

int main()
{
  std::map<int, std::shared_ptr<int>> map{
  { 0, std::make_shared<int>(0) },
  { 1, std::make_shared<int>(1) },
  { 2, std::make_shared<int>(2) }
};

  return 0;
}

Immediately after initializing the map, smart pointer 0 is freed, and its entry remains on the map. Smart pointers 1 and 2 remain. On returning, all three smart pointers are freed, resulting in double deletion on the first smart pointer. This reuslts in the following message:
HEAP: Free Heap block 3fc7a0 modified at 3fc7cc after it was freed

Additionally, this also occurs while initializing a container (tried vector and list) containing a pair containing a smart pointer.
i.e. std::vector<std::pair<int, std::shared_ptr<int>>> value { ... }

Microsoft (R) C/C++ Optimizing Compiler Version 18.00.21005.1 for x86
Microsoft (R) Incremental Linker Version 12.00.21005.1
Microsoft Visual Studio Professional 2013
Version 12.0.21005.1 REL
Sign in to post a comment.
Posted by Microsoft on 3/27/2014 at 11:28 AM
Hi:
    Thanks for reporting the issue.
    A fix for this issue has been checked into the compiler sources. The fix should show up in the future release of Visual C++.

Xiang Fan
Visual C++ Team
Posted by Microsoft on 3/18/2014 at 12:40 AM
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been reproduced and has been routed to the appropriate VS development team for review. We will contact you if we require any additional information. If you require immediate assistance with this issue, please contact product support at http://support.microsoft.com/ph/1117.
Posted by Microsoft on 3/17/2014 at 6:38 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)