#4256 closed Bugs (fixed)
boost::make_shared() may issue stack overflow while constructing large objects
Reported by: | Owned by: | Peter Dimov | |
---|---|---|---|
Milestone: | Component: | smart_ptr | |
Version: | Boost 1.50.0 | Severity: | Regression |
Keywords: | make_shared stack overflow | Cc: |
Description
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 >= "stack size" / 3. In release builds due to optimizations, the stack overflow exception issued with A_Size >= "stack size" / 2.
#include <cstddef> #include <boost/make_shared.hpp> #include <boost/shared_ptr.hpp> const std::size_t A_Size = 512; struct A { char buf_[A_Size * 1024]; }; int main() { boost::shared_ptr<A> pa(boost::make_shared<A>()); //boost::shared_ptr<A> pa(new A()); return 0; }
Change History (12)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
Status: | new → assigned |
---|
comment:3 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:4 by , 11 years ago
I ran into this using 1.47 yesterday
I was in debug mode VS2010. I needed a pretty large receive buffer for a TCPReceiver.
The first enum caused a stack overflow error. Reducing the size stopped the error.
Release mode did not complain about either size.
struct TCPRawData{
void* pParent;
this blew the stack - enum{max_length = 1048576};
this was fine - enum{max_length = 500000};
char buffer[max_length];
int bytesReceived;
TCPRawData(void* parent): pParent(parent){}
};
comment:5 by , 11 years ago
This was the offending code from the TCPReceiver.
TCPReadBuff = boost::make_shared<TCPRawData>(this);
comment:6 by , 10 years ago
Milestone: | Boost 1.44.0 |
---|---|
Resolution: | fixed |
Severity: | Problem → Regression |
Status: | closed → reopened |
Version: | Boost 1.43.0 → Boost 1.50.0 |
This is not fixed, at least in Boost 1.50. It's reproducible in VS2008 Debug build. Please reopen.
comment:7 by , 10 years ago
The above example (with A_Size = 512) works for me with the latest Boost and VS2005 Debug.
comment:10 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
(In [69250]) Fix make_shared to not copy the deleter. Refs #4256. Refs #3875.