Modify

Opened 7 years ago

Closed 5 years ago

Last modified 3 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;
}

Attachments (0)

Change History (12)

comment:1 Changed 7 years ago by Peter Dimov

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

comment:2 Changed 7 years ago by Peter Dimov

Status: newassigned

comment:3 Changed 7 years ago by Peter Dimov

Resolution: fixed
Status: assignedclosed

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

comment:4 Changed 6 years ago by cameron.k.ward@…

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 Changed 6 years ago by cameron.k.ward@…

This was the offending code from the TCPReceiver.

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

comment:6 Changed 5 years ago by szakharchenko@…

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 Changed 5 years ago by Peter Dimov

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

comment:8 Changed 5 years ago by Peter Dimov

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

comment:9 Changed 5 years ago by Peter Dimov

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

comment:10 Changed 5 years ago by Peter Dimov

Resolution: fixed
Status: reopenedclosed

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

comment:11 Changed 3 years ago by anonymous

Not fixed in boost 1.55 either

comment:12 Changed 3 years ago by Peter Dimov

Can you please tell me how to reproduce?

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Peter Dimov.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.