Modify

Opened 7 years ago

Closed 4 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: pdimov
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 6 years ago by pdimov

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

comment:2 Changed 6 years ago by pdimov

  • Status changed from new to assigned

comment:3 Changed 6 years ago by pdimov

  • Resolution set to fixed
  • Status changed from assigned to closed

(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 4 years ago by szakharchenko@…

  • Milestone Boost 1.44.0 deleted
  • Resolution fixed deleted
  • Severity changed from Problem to Regression
  • Status changed from closed to reopened
  • Version changed from Boost 1.43.0 to 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 Changed 4 years ago by pdimov

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

comment:8 Changed 4 years ago by pdimov

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

comment:9 Changed 4 years ago by pdimov

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

comment:10 Changed 4 years ago by pdimov

  • Resolution set to fixed
  • Status changed from reopened to closed

(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 pdimov

Can you please tell me how to reproduce?

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain pdimov.
The resolution will be deleted. Next status will be 'reopened'.
Author


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

 
Note: See TracTickets for help on using tickets.