Summary:
There were a few places where we were calling malloc/reallaoc/free without
including cstdlib (or stdlib.h). This is broken, but it worked because
other headers that we were including included stdlib.h. However, on a
platform where this wasn't true, it broke the Thrift build. This change
adds the proper includes. It also changes malloc to std::malloc (same
with realloc and free) in a few places, because that is the correct way
of doing it when you include cstdlib.
Reviewed By: mcslee
Test Plan: Compiled Thrift.
Revert Plan: ok
Other Notes:
This bug was noticed by a Thrudb user, and the patch was sent in by
Ross McFarland.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665487
13f79535-47bb-0310-9956-
ffa450edef68
AC_CHECK_HEADERS([netinet/in.h])
AC_CHECK_HEADERS([pthread.h])
AC_CHECK_HEADERS([stddef.h])
+AC_CHECK_HEADERS([stdlib.h])
AC_CHECK_HEADERS([sys/socket.h])
AC_CHECK_HEADERS([sys/time.h])
AC_CHECK_HEADERS([unistd.h])
// Use the heap here to prevent stack overflow for v. large strings
if (size > string_buf_size_ || string_buf_ == NULL) {
- string_buf_ = (uint8_t*)realloc(string_buf_, (uint32_t)size);
+ string_buf_ = (uint8_t*)std::realloc(string_buf_, (uint32_t)size);
if (string_buf_ == NULL) {
string_buf_size_ = 0;
throw TProtocolException(TProtocolException::UNKNOWN, "Out of memory in TBinaryProtocol::readString");
~TBinaryProtocol() {
if (string_buf_ != NULL) {
- free(string_buf_);
+ std::free(string_buf_);
string_buf_size_ = 0;
}
}
while (readWant_ > readBufferSize_) {
readBufferSize_ *= 2;
}
- readBuffer_ = (uint8_t*)realloc(readBuffer_, readBufferSize_);
+ readBuffer_ = (uint8_t*)std::realloc(readBuffer_, readBufferSize_);
if (readBuffer_ == NULL) {
GlobalOutput("TConnection::workSocket() realloc");
close();
#include <transport/TTransportUtils.h>
#include <concurrency/ThreadManager.h>
#include <stack>
+#include <cstdlib>
#include <event.h>
namespace facebook { namespace thrift { namespace server {
// Constructor
TConnection(int socket, short eventFlags, TNonblockingServer *s) {
- readBuffer_ = (uint8_t*)malloc(1024);
+ readBuffer_ = (uint8_t*)std::malloc(1024);
if (readBuffer_ == NULL) {
throw new facebook::thrift::TException("Out of memory.");
}
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
+#include <cstdlib>
#include <iostream>
#include <sys/stat.h>
}
eventInfo* toEnqueue = new eventInfo();
- toEnqueue->eventBuff_ = (uint8_t *)malloc((sizeof(uint8_t) * eventLen) + 4);
+ toEnqueue->eventBuff_ = (uint8_t *)std::malloc((sizeof(uint8_t) * eventLen) + 4);
// first 4 bytes is the event length
memcpy(toEnqueue->eventBuff_, (void*)(&eventLen), 4);
// actual event contents
// See accompanying file LICENSE or visit the Thrift site at:
// http://developers.facebook.com/thrift/
+#include <cstdlib>
+
#include "THttpClient.h"
#include "TSocket.h"
}
void THttpClient::init() {
- httpBuf_ = (char*)malloc(httpBufSize_+1);
+ httpBuf_ = (char*)std::malloc(httpBufSize_+1);
if (httpBuf_ == NULL) {
throw TTransportException("Out of memory.");
}
THttpClient::~THttpClient() {
if (httpBuf_ != NULL) {
- free(httpBuf_);
+ std::free(httpBuf_);
}
}
uint32_t avail = httpBufSize_ - httpBufLen_;
if (avail <= (httpBufSize_ / 4)) {
httpBufSize_ *= 2;
- httpBuf_ = (char*)realloc(httpBuf_, httpBufSize_+1);
+ httpBuf_ = (char*)std::realloc(httpBuf_, httpBufSize_+1);
if (httpBuf_ == NULL) {
throw TTransportException("Out of memory.");
}
bufferSize_ *= 2;
avail = bufferSize_ - wPos_;
}
- buffer_ = (uint8_t*)realloc(buffer_, bufferSize_);
+ buffer_ = (uint8_t*)std::realloc(buffer_, bufferSize_);
if (buffer_ == NULL) {
throw TTransportException("Out of memory.");
}
// Double the size of the underlying buffer if it is full
if (rLen_ == rBufSize_) {
rBufSize_ *=2;
- rBuf_ = (uint8_t *)realloc(rBuf_, sizeof(uint8_t) * rBufSize_);
+ rBuf_ = (uint8_t *)std::realloc(rBuf_, sizeof(uint8_t) * rBufSize_);
}
// try to fill up the buffer
while ((len + wLen_) >= newBufSize) {
newBufSize *= 2;
}
- wBuf_ = (uint8_t *)realloc(wBuf_, sizeof(uint8_t) * newBufSize);
+ wBuf_ = (uint8_t *)std::realloc(wBuf_, sizeof(uint8_t) * newBufSize);
wBufSize_ = newBufSize;
}
#ifndef _THRIFT_TRANSPORT_TTRANSPORTUTILS_H_
#define _THRIFT_TRANSPORT_TTRANSPORTUTILS_H_ 1
+#include <cstdlib>
#include <string>
#include <algorithm>
#include <transport/TTransport.h>
void initCommon(uint8_t* buf, uint32_t size, bool owner, uint32_t wPos) {
if (buf == NULL && size != 0) {
assert(owner);
- buf = (uint8_t*)malloc(size);
+ buf = (uint8_t*)std::malloc(size);
if (buf == NULL) {
throw TTransportException("Out of memory");
}
~TMemoryBuffer() {
if (owner_) {
- free(buffer_);
+ std::free(buffer_);
buffer_ = NULL;
}
}
pipeOnRead_ = true;
pipeOnWrite_ = false;
- rBuf_ = (uint8_t*) malloc(sizeof(uint8_t) * rBufSize_);
- wBuf_ = (uint8_t*) malloc(sizeof(uint8_t) * wBufSize_);
+ rBuf_ = (uint8_t*) std::malloc(sizeof(uint8_t) * rBufSize_);
+ wBuf_ = (uint8_t*) std::malloc(sizeof(uint8_t) * wBufSize_);
}
TPipedTransport(boost::shared_ptr<TTransport> srcTrans,
rBufSize_(512), rPos_(0), rLen_(0),
wBufSize_(sz), wLen_(0) {
- rBuf_ = (uint8_t*) malloc(sizeof(uint8_t) * rBufSize_);
- wBuf_ = (uint8_t*) malloc(sizeof(uint8_t) * wBufSize_);
+ rBuf_ = (uint8_t*) std::malloc(sizeof(uint8_t) * rBufSize_);
+ wBuf_ = (uint8_t*) std::malloc(sizeof(uint8_t) * wBufSize_);
}
~TPipedTransport() {
- free(rBuf_);
- free(wBuf_);
+ std::free(rBuf_);
+ std::free(wBuf_);
}
bool isOpen() {
// Double the size of the underlying buffer if it is full
if (rLen_ == rBufSize_) {
rBufSize_ *=2;
- rBuf_ = (uint8_t *)realloc(rBuf_, sizeof(uint8_t) * rBufSize_);
+ rBuf_ = (uint8_t *)std::realloc(rBuf_, sizeof(uint8_t) * rBufSize_);
}
// try to fill up the buffer