Modify

Ticket #4256 (closed Bugs: fixed)

Opened 4 years ago

Last modified 14 months ago

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

Change History

comment:1 Changed 3 years ago by pdimov

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

comment:2 Changed 3 years ago by pdimov

  • Status changed from new to assigned

comment:3 Changed 3 years ago by pdimov

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

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

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

This was the offending code from the TCPReceiver.

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

comment:6 Changed 14 months ago by szakharchenko@…

  • Status changed from closed to reopened
  • Version changed from Boost 1.43.0 to Boost 1.50.0
  • Resolution fixed deleted
  • Severity changed from Problem to Regression
  • Milestone Boost 1.44.0 deleted

This is not fixed, at least in Boost 1.50. It's reproducible in VS2008 Debug build. Please reopen.

comment:7 Changed 14 months ago by pdimov

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

comment:8 Changed 14 months ago by pdimov

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

comment:9 Changed 14 months ago by pdimov

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

comment:10 Changed 14 months ago by pdimov

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

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

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
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.