Boost C++ Libraries: Ticket #4256: boost::make_shared() may issue stack overflow while constructing large objects https://svn.boost.org/trac10/ticket/4256 <p> By default stack size for windows executable is 1Mb. The program below fails with stack overflow exception. In debug builds the stack overflow exception issued with A_Size &gt;= "stack size" / 3. In release builds due to optimizations, the stack overflow exception issued with A_Size &gt;= "stack size" / 2. </p> <pre class="wiki">#include &lt;cstddef&gt; #include &lt;boost/make_shared.hpp&gt; #include &lt;boost/shared_ptr.hpp&gt; const std::size_t A_Size = 512; struct A { char buf_[A_Size * 1024]; }; int main() { boost::shared_ptr&lt;A&gt; pa(boost::make_shared&lt;A&gt;()); //boost::shared_ptr&lt;A&gt; pa(new A()); return 0; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4256 Trac 1.4.3 Peter Dimov Thu, 24 Feb 2011 21:51:25 GMT <link>https://svn.boost.org/trac10/ticket/4256#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4256#comment:1</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/69250" title="Fix make_shared to not copy the deleter. Refs #4256. Refs #3875.">[69250]</a>) Fix make_shared to not copy the deleter. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4256" title="#4256: Bugs: boost::make_shared() may issue stack overflow while constructing large ... (closed: fixed)">#4256</a>. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3875" title="#3875: Bugs: make_shared, allocate_shared fail compile with aligned objects in msvc (closed: fixed)">#3875</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Thu, 24 Feb 2011 21:54:24 GMT</pubDate> <title>status changed https://svn.boost.org/trac10/ticket/4256#comment:2 https://svn.boost.org/trac10/ticket/4256#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket Peter Dimov Tue, 22 Mar 2011 23:38:15 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4256#comment:3 https://svn.boost.org/trac10/ticket/4256#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/70436" title="Merge [69250] to release. Fixes #4256. Fixes #3875.">[70436]</a>) Merge <a class="changeset" href="https://svn.boost.org/trac10/changeset/69250" title="Fix make_shared to not copy the deleter. Refs #4256. Refs #3875.">[69250]</a> to release. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4256" title="#4256: Bugs: boost::make_shared() may issue stack overflow while constructing large ... (closed: fixed)">#4256</a>. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3875" title="#3875: Bugs: make_shared, allocate_shared fail compile with aligned objects in msvc (closed: fixed)">#3875</a>. </p> Ticket cameron.k.ward@… Mon, 07 Nov 2011 17:42:38 GMT <link>https://svn.boost.org/trac10/ticket/4256#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4256#comment:4</guid> <description> <p> I ran into this using 1.47 yesterday </p> <p> I was in debug mode VS2010. I needed a pretty large receive buffer for a TCPReceiver. </p> <p> The first enum caused a stack overflow error. Reducing the size stopped the error. </p> <p> Release mode did not complain about either size. </p> <p> struct TCPRawData{ </p> <blockquote> <p> void* pParent; </p> </blockquote> <blockquote> <p> this blew the stack - enum{max_length = 1048576}; </p> </blockquote> <p> </p> <blockquote> <p> this was fine - enum{max_length = 500000}; </p> </blockquote> <blockquote> <p> char buffer[max_length]; </p> </blockquote> <blockquote> <p> int bytesReceived; </p> </blockquote> <blockquote> <p> TCPRawData(void* parent): pParent(parent){} </p> </blockquote> <p> }; </p> </description> <category>Ticket</category> </item> <item> <author>cameron.k.ward@…</author> <pubDate>Mon, 07 Nov 2011 17:44:38 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4256#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4256#comment:5</guid> <description> <p> This was the offending code from the TCPReceiver. </p> <p> TCPReadBuff = boost::make_shared&lt;TCPRawData&gt;(this); </p> </description> <category>Ticket</category> </item> <item> <author>szakharchenko@…</author> <pubDate>Thu, 28 Feb 2013 06:30:24 GMT</pubDate> <title>status, version, severity changed; resolution, milestone deleted https://svn.boost.org/trac10/ticket/4256#comment:6 https://svn.boost.org/trac10/ticket/4256#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>version</strong> <span class="trac-field-old">Boost 1.43.0</span> → <span class="trac-field-new">Boost 1.50.0</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> <li><strong>severity</strong> <span class="trac-field-old">Problem</span> → <span class="trac-field-new">Regression</span> </li> <li><strong>milestone</strong> <span class="trac-field-deleted">Boost 1.44.0</span> </li> </ul> <p> This is not fixed, at least in Boost 1.50. It's reproducible in VS2008 Debug build. Please reopen. </p> Ticket Peter Dimov Thu, 28 Feb 2013 07:01:37 GMT <link>https://svn.boost.org/trac10/ticket/4256#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4256#comment:7</guid> <description> <p> The above example (with A_Size = 512) works for me with the latest Boost and VS2005 Debug. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Thu, 28 Feb 2013 07:32:40 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4256#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4256#comment:8</guid> <description> <p> It does fail with A_Size=1024 though, which is probably what you mean. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Thu, 28 Feb 2013 08:02:13 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4256#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4256#comment:9</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/83198" title="Avoid stack overflow in make_shared. Refs #4256.">[83198]</a>) Avoid stack overflow in make_shared. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4256" title="#4256: Bugs: boost::make_shared() may issue stack overflow while constructing large ... (closed: fixed)">#4256</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Thu, 07 Mar 2013 08:18:51 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4256#comment:10 https://svn.boost.org/trac10/ticket/4256#comment:10 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/83341" title="Merged revision(s) 83198 from trunk: Avoid stack overflow in ...">[83341]</a>) Merged revision(s) 83198 from trunk: Avoid stack overflow in make_shared. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4256" title="#4256: Bugs: boost::make_shared() may issue stack overflow while constructing large ... (closed: fixed)">#4256</a>. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7965" title="#7965: Bugs: make_shared causes stack overflow with large objects (closed: fixed)">#7965</a>. </p> Ticket anonymous Tue, 22 Apr 2014 14:52:54 GMT <link>https://svn.boost.org/trac10/ticket/4256#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4256#comment:11</guid> <description> <p> Not fixed in boost 1.55 either </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Tue, 22 Apr 2014 15:15:29 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4256#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4256#comment:12</guid> <description> <p> Can you please tell me how to reproduce? </p> </description> <category>Ticket</category> </item> </channel> </rss>