Bad_alloc on remote server only on Travis

I have this weird ‘std::bad_alloc’ thrown only during my test using travis-ci servers. I have tested my code on several machines, with the same compilers options, and I don’t call any external library (only standard c++11).

./convexhull ../examples/convexhull/instances/size100space10.csv 1
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
/home/travis/ line 45:  3957 Aborted                 (core dumped) ./conve

Does anyone have an idea on what could be the cause of the bad-alloc in a similar context? Is there a quicker way than using valgrind with travis-ci?

The standard library implementation allocates count bytes from free store. In case of a failure, the standard library implementation calls the function pointer returned by std::get_new_handler and repeats allocation attempts until new the handler does not return or becomes a null pointer, at which time it throws std::bad_alloc. In your case, std::bad_alloc means that you requested to allocate data on heap but there was not enough memory.

This can be a direct request with new or an indirect one, like creating a very big std::vector. Note, that std::bad_alloc is rarely encountered anymore for several reasons. First of all, by default Linux always successfully allocates enough memory because “real allocation” is made when you try to access the kernel, unless you’re using a distribution like Gentoo where you can easily mess things up with your swap partition.

When you’re talking about a Travis CI server, it’s totally different. We have to provide reliable infrastructure that runs unreliable and sometimes untrusted code. There are rate-limits we have in place so this doesn’t eat much or if any of our core RAM up.

My suggestion is you have to use less RAM in your tests and reduce the size of your test data. I haven’t seen a bad_alloc in so long, so for me this answer is very obvious.

1 Like

Hey @Montana,

It’s a shame you have a “know-it-all” attitude, you are right there’s no doubt and are a brilliant mind in the CI space but you don’t need to be condescending in every post. That being said I appreciate your work in this community. Thank you for your really helpful answer.