Search code examples
c++opencvstack-overflowstdmod-pagespeed

C++ std::bad_alloc from stack allocation?


We have a test in our code that tries to tickle a stack-overflow bug (in an old modified version of OpenCV). AFAIK, the test should SEGV if there is actually a stack overflow.

One of our users is getting a test failure because of exception std::bad_alloc thrown. It sounds like this exception is only thrown for heap allocations (results of new operator - http://www.cplusplus.com/reference/std/new/bad_alloc/).

Could this be happening because of a large stack allocation?

For reference, the test is: http://code.google.com/p/modpagespeed/source/browse/trunk/src/net/instaweb/rewriter/image_test.cc#826

and the bug report is: http://code.google.com/p/modpagespeed/issues/detail?id=528


Solution

  • No, this exception is thrown only from operator new/new[].

    It could happen even if you don't use operator new/new[] anywhere - the reason - STL containers do use it.