When malloc/realloc fail, we've typically just thrown a TException. This
allows a server that should simply crash when out of memory to survive
in a strage state, with various bad consequences. Instead, we should
throw bad_alloc and just not catch it (or if we decide to, be very
careful to respond properly).
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@
1005167 13f79535-47bb-0310-9956-
ffa450edef68
if (size > this->string_buf_size_ || this->string_buf_ == NULL) {
void* new_string_buf = std::realloc(this->string_buf_, (uint32_t)size);
if (new_string_buf == NULL) {
- throw TProtocolException(TProtocolException::UNKNOWN,
- "Out of memory in TBinaryProtocolT::readString");
+ throw std::bad_alloc();
}
this->string_buf_ = (uint8_t*)new_string_buf;
this->string_buf_size_ = size;
if (size > string_buf_size_ || string_buf_ == NULL) {
void* new_string_buf = std::realloc(string_buf_, (uint32_t)size);
if (new_string_buf == NULL) {
- throw TProtocolException(TProtocolException::UNKNOWN, "Out of memory in TCompactProtocol::readString");
+ throw std::bad_alloc();
}
string_buf_ = (uint8_t*)new_string_buf;
string_buf_size_ = size;
// Allocate into a new pointer so we don't bork ours if it fails.
void* new_buffer = std::realloc(buffer_, new_size);
if (new_buffer == NULL) {
- throw TTransportException("Out of memory.");
+ throw std::bad_alloc();
}
bufferSize_ = new_size;
assert(owner);
buf = (uint8_t*)std::malloc(size);
if (buf == NULL) {
- throw TTransportException("Out of memory");
+ throw std::bad_alloc();
}
}
eventInfo* toEnqueue = new eventInfo();
toEnqueue->eventBuff_ = (uint8_t *)std::malloc((sizeof(uint8_t) * eventLen) + 4);
+ if (toEnqueue->eventBuff_ == NULL) {
+ throw std::bad_alloc();
+ }
// first 4 bytes is the event length
memcpy(toEnqueue->eventBuff_, (void*)(&eventLen), 4);
// actual event contents
void THttpTransport::init() {
httpBuf_ = (char*)std::malloc(httpBufSize_+1);
if (httpBuf_ == NULL) {
- throw TTransportException("Out of memory.");
+ throw std::bad_alloc();
}
httpBuf_[httpBufLen_] = '\0';
}
httpBufSize_ *= 2;
httpBuf_ = (char*)std::realloc(httpBuf_, httpBufSize_+1);
if (httpBuf_ == NULL) {
- throw TTransportException("Out of memory.");
+ throw std::bad_alloc();
}
}
pipeOnWrite_ = false;
rBuf_ = (uint8_t*) std::malloc(sizeof(uint8_t) * rBufSize_);
+ if (rBuf_ == NULL) {
+ throw std::bad_alloc();
+ }
wBuf_ = (uint8_t*) std::malloc(sizeof(uint8_t) * wBufSize_);
+ if (wBuf_ == NULL) {
+ throw std::bad_alloc();
+ }
}
TPipedTransport(boost::shared_ptr<TTransport> srcTrans,
wBufSize_(sz), wLen_(0) {
rBuf_ = (uint8_t*) std::malloc(sizeof(uint8_t) * rBufSize_);
+ if (rBuf_ == NULL) {
+ throw std::bad_alloc();
+ }
wBuf_ = (uint8_t*) std::malloc(sizeof(uint8_t) * wBufSize_);
+ if (wBuf_ == NULL) {
+ throw std::bad_alloc();
+ }
}
~TPipedTransport() {