Opened 12 years ago

Closed 10 years ago

Last modified 9 years ago

#4256 closed Bugs (fixed)

boost::make_shared() may issue stack overflow while constructing large objects

Reported by: faridz@… 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 Peter Dimov, 12 years ago

(In [69250]) Fix make_shared to not copy the deleter. Refs #4256. Refs #3875.

comment:2 by Peter Dimov, 12 years ago

Status: newassigned

comment:3 by Peter Dimov, 12 years ago

Resolution: fixed
Status: assignedclosed

(In [70436]) Merge [69250] to release. Fixes #4256. Fixes #3875.

comment:4 by cameron.k.ward@…, 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 cameron.k.ward@…, 11 years ago

This was the offending code from the TCPReceiver.

TCPReadBuff = boost::make_shared<TCPRawData>(this);

comment:6 by szakharchenko@…, 10 years ago

Milestone: Boost 1.44.0
Resolution: fixed
Severity: ProblemRegression
Status: closedreopened
Version: Boost 1.43.0Boost 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 Peter Dimov, 10 years ago

The above example (with A_Size = 512) works for me with the latest Boost and VS2005 Debug.

comment:8 by Peter Dimov, 10 years ago

It does fail with A_Size=1024 though, which is probably what you mean.

comment:9 by Peter Dimov, 10 years ago

(In [83198]) Avoid stack overflow in make_shared. Refs #4256.

comment:10 by Peter Dimov, 10 years ago

Resolution: fixed
Status: reopenedclosed

(In [83341]) Merged revision(s) 83198 from trunk: Avoid stack overflow in make_shared. Fixes #4256. Fixes #7965.

comment:11 by anonymous, 9 years ago

Not fixed in boost 1.55 either

comment:12 by Peter Dimov, 9 years ago

Can you please tell me how to reproduce?

Note: See TracTickets for help on using tickets.