[Bro] pcap_next Question

Chris Crawford christopher.p.crawford at gmail.com
Thu Aug 9 03:43:47 PDT 2012

I don't think that is quite right for C++.

In this case, I have a stack trace showing that std::bad_alloc is
thrown, but never caught.

For a less official explanation, here's a stackoverflow post that
addresses the same issue:

Cplusplus.com has a more official explanation.

Here is a high level view of how new works in the C++ STL:

If you take a look at both new and new[], you can see that in either
case "On failure, it throws a bad_alloc exception."

This explains std::nothrow and how to catch the error:

To get the effect you're talking about in C++, you have to explicitly
cast a new operation with std::nothrow:

Here is another example:

I did a bit a of Googling to find some documentation that would say
that the new operator returns a NULL pointer by defaut, versus
returning std::bad_alloc.  The only thing I could really find was a an
bug in Visual C++ that was documented in this KB article:


On Thu, Aug 9, 2012 at 2:01 AM, Vern Paxson <vern at icir.org> wrote:
>>        block = new u_char[size];
>>        if ( ! block )
>>                 reporter->InternalError("out of memory");
>> Since the new operator is throwing a std::bad_alloc error, that line
>> should be surrounded with a bit of error handling like in the attached
>> patch file.
> I thought 'new' is defined to return a nil pointer upon memory exhaustion.
> Is that wrong / dates me horribly?
>                 Vern

More information about the Bro mailing list