[Bro] pcap_next Question

Chris Crawford christopher.p.crawford at gmail.com
Thu Aug 9 15:49:38 PDT 2012


Oh cool, that seems like a much cleaner approach.

The if-statement that follows still doesn't make sense to me, though:

       if ( ! block )
                reporter->InternalError("out of memory");

If the handler in bro_new_handler() aborts, then this never executes.
If the handler succeeds in making more storage available and returns,
it seems to me that this if block still wouldn't execute because block
would not be null.  If this if-statement did execute, then it seems
like the logic would be off -- you're not out of memory yet, because
the handler just returned with some after a second try.

It seems like a logical place to print an "out of memory" message to
the logs would be just before an abort in the function registered in
bro_new_handler() to handle catching std::bad_alloc errors.

-Chris

On Thu, Aug 9, 2012 at 6:23 PM, Robin Sommer <robin at icir.org> wrote:
>
> On Thu, Aug 09, 2012 at 06:43 -0400, Chris Crawford wrote:
>
>> I don't think that is quite right for C++.
>
> Yeah, it throws an exception by default. However, there's a way to
> catch a failing new by setting a corresponding handler, see:
>
>     http://www.cplusplus.com/reference/std/new/set_new_handler
>
> The funny thing is that I thought we did that already; and in fact
> there's a function bro_new_handler() that reports an out of memory
> error and aborts. However, we must have lost the call to the
> corresponding set_new_handler() at some point: I don't find
> bro_new_handler() used anywhere. So what we should do is add that back
> in; I'll do that.
>
> Robin
>
> --
> Robin Sommer * Phone +1 (510) 722-6541 * robin at icir.org
> ICSI/LBNL    * Fax   +1 (510) 666-2956 *   www.icir.org



More information about the Bro mailing list